Quels sont les avantages de Visual Studio ?

Mastering Visual Studio: Shortcuts & Editor Tips

26/11/2015

Rating: 4.71 (16331 votes)

Visual Studio is a powerhouse integrated development environment (IDE) that offers an unparalleled array of features to streamline coding, debugging, and project management. For developers looking to maximise their efficiency, understanding how to swiftly access commands and leverage the editor's advanced capabilities is paramount. This guide will delve into the world of Visual Studio keyboard shortcuts and explore the rich functionalities of its code editor, transforming how you interact with your projects and code.

Comment accéder à différentes commandes et fenêtres dans Visual Studio ?
Vous pouvez accéder à diverses commandes et fenêtres dans Visual Studio en choisissant le raccourci clavier approprié. Cette page répertorie les raccourcis de commande par défaut pour le profil général, que vous avez peut-être choisi lors de l’installation de Visual Studio.
Table

Mastering Visual Studio with Keyboard Shortcuts

Keyboard shortcuts are the cornerstone of a productive development workflow. In Visual Studio, they provide a rapid pathway to various commands and windows, allowing you to keep your hands on the keyboard and maintain focus. While Visual Studio offers a default set of shortcuts, typically based on the 'General' profile chosen during installation, you have the flexibility to discover and even customise them to fit your unique preferences and work style.

Finding and Customising Shortcuts

To identify the shortcut for any command or to assign a new one, navigate to the Tools menu, select Options, expand the Environment node, and then choose Keyboard. This dialogue box provides a comprehensive list of all commands and their assigned shortcuts. You can search for commands by name or by their current shortcut, making it easy to discover new efficiencies or reconfigure existing ones.

Printable Shortcut Cheat Sheet

For a quick reference, a printable shortcut cheat sheet for Visual Studio is often available from Microsoft's official documentation. This can be an invaluable resource to keep handy as you familiarise yourself with the most frequently used shortcuts.

Key Global Shortcuts for Enhanced Productivity

Global shortcuts are those that are applicable across almost any tool window within Visual Studio, regardless of the active context. Mastering these can significantly reduce reliance on the mouse, making your development process smoother and faster. Below is a selection of some of the most popular and universally useful global shortcuts.

Build Commands

Efficiently manage your project builds with these essential shortcuts.

CommandKeyboard ShortcutCommand ID
Build SolutionCtrl+Shift+BBuild.BuildSolution
CancelCtrl+BreakBuild.Cancel
CompileCtrl+F7Build.Compile
Run Code Analysis on SolutionAlt+F11Build.RunCodeAnalysisonSolution

Debug Commands

Navigate through your code, identify issues, and control execution flow with these debugging shortcuts.

CommandKeyboard ShortcutCommand ID
Break AllCtrl+Alt+BreakDebug.BreakAll
Delete All BreakpointsCtrl+Shift+F9Debug.DeleteAllBreakpoints
ExceptionsCtrl+Alt+EDebug.Exceptions
Quick WatchShift+F9 or Ctrl+Alt+QDebug.QuickWatch
RestartCtrl+Shift+F5Debug.Restart
StartF5Debug.Start
Start Without DebuggingCtrl+F5Debug.StartWithoutDebugging
Step IntoF11Debug.StepInto
Step OutShift+F11Debug.StepOut
Step OverF10Debug.StepOver
Stop DebuggingShift+F5Debug.StopDebugging
Toggle BreakpointF9Debug.ToggleBreakpoint

Edit Commands

These shortcuts are indispensable for everyday code manipulation and text editing.

CommandKeyboard ShortcutCommand ID
Comment SelectionCtrl+K, Ctrl+CEdit.CommentSelection
CopyCtrl+C or Ctrl+InsertEdit.Copy
CutCtrl+X or Shift+DeleteEdit.Cut
DeleteDeleteEdit.Delete
FindCtrl+FEdit.Find
Find All ReferencesShift+F12Edit.FindAllReferences
Find in FilesCtrl+Shift+FEdit.FindinFiles
Format DocumentCtrl+K, Ctrl+DEdit.FormatDocument
Go To DefinitionF12Edit.GoToDefinition
Insert SnippetCtrl+K, Ctrl+XEdit.InsertSnippet
PasteCtrl+V or Shift+InsertEdit.Paste
RedoCtrl+Y or Ctrl+Shift+ZEdit.Redo
ReplaceCtrl+HEdit.Replace
Select AllCtrl+AEdit.SelectAll
UndoCtrl+Z or Alt+BackspaceEdit.Undo

File Commands

Quickly manage your project files and solutions.

CommandKeyboard ShortcutCommand ID
New FileCtrl+NFile.NewFile
New ProjectCtrl+Shift+NFile.NewProject
Open FileCtrl+OFile.OpenFile
Save AllCtrl+Shift+SFile.SaveAll
Save Selected ItemsCtrl+SFile.SaveSelectedItems

Project Commands

Add new items and manage your project structure with these shortcuts.

CommandKeyboard ShortcutCommand ID
Add Existing ItemShift+Alt+AProject.AddExistingItem
Add New ItemCtrl+Shift+AProject.AddNewItem

Refactoring Commands

Streamline your code with powerful refactoring operations.

CommandKeyboard ShortcutCommand ID
Extract MethodCtrl+R, Ctrl+MRefactor.ExtractMethod
RenameCtrl+R, Ctrl+RRefactor.Rename

Tools Commands

Access various utility tools within the IDE.

CommandKeyboard ShortcutCommand ID
Attach to ProcessCtrl+Alt+PTools.AttachtoProcess

View Commands

Quickly open and navigate between different Visual Studio windows.

Comment accéder à différentes commandes et fenêtres dans Visual Studio ?
Vous pouvez accéder à diverses commandes et fenêtres dans Visual Studio en choisissant le raccourci clavier approprié. Cette page répertorie les raccourcis de commande par défaut pour le profil général, que vous avez peut-être choisi lors de l’installation de Visual Studio.
CommandKeyboard ShortcutCommand ID
Error ListCtrl+\, Ctrl+EView.ErrorList
OutputCtrl+Alt+OView.Output
Properties WindowF4View.PropertiesWindow
Solution ExplorerCtrl+Alt+LView.SolutionExplorer
ToolboxCtrl+Alt+XView.Toolbox

Window Commands

Manage your open documents and tool windows efficiently.

CommandKeyboard ShortcutCommand ID
Activate Document WindowEscWindow.ActivateDocumentWindow
Close Document WindowCtrl+F4Window.CloseDocumentWindow
Next Document WindowCtrl+F6Window.NextDocumentWindow
Next Document Window NavCtrl+TabWindow.NextDocumentWindowNav

Context-Specific Shortcuts: Tailoring Your Workflow

Beyond global shortcuts, Visual Studio offers context-specific shortcuts that become active when you are working within a particular editor, designer, or tool window. These allow for highly specialised and efficient interactions within that specific environment. Below are examples from various common contexts.

Text Editor Shortcuts

The text editor is where most of your coding happens, and these shortcuts are crucial for efficient typing and navigation.

CommandKeyboard ShortcutCommand ID
Break LineEnter or Shift+EnterEdit.BreakLine
Collapse All OutliningCtrl+M, Ctrl+AEdit.CollapseAllOutlining
Contract SelectionShift+Alt+-Edit.ContractSelection
Document EndCtrl+EndEdit.DocumentEnd
Expand All OutliningCtrl+M, Ctrl+XEdit.ExpandAllOutlining
Go To BraceCtrl+]Edit.GotoBrace
Insert TabTabEdit.InsertTab
Line CutCtrl+LEdit.LineCut
Move Selected Lines DownAlt+Down ArrowEdit.MoveSelectedLinesDown
Next Highlighted ReferenceCtrl+Shift+Down ArrowEdit.NextHighlightedReference
Peek DefinitionAlt+F12Edit.PeekDefinition
Toggle BookmarkCtrl+K, Ctrl+KEdit.ToggleBookmark
Word NextCtrl+Right ArrowEdit.WordNext

HTML Editor (Design View) Shortcuts

When working with visual design for web pages, these shortcuts can be very helpful.

CommandKeyboard ShortcutCommand ID
Move Control DownCtrl+Down ArrowEdit.MoveControlDown
BoldCtrl+BFormat.Bold
Insert BookmarkCtrl+Shift+LFormat.InsertBookmark
Show Smart TagShift+Alt+F10View.ShowSmartTag

SQL Editor (Text & Query) Shortcuts

For database developers, these shortcuts enhance interaction with SQL scripts and queries.

CommandKeyboard ShortcutCommand ID
Commit All EditsShift+Alt+UCommitAllEdits
Execute With DebuggerAlt+F5SQL.ExecuteWithDebugger
Fully Qualify NamesCtrl+R, Q or Ctrl+R, Ctrl+QSQL.FullyqualifyNames
TSql Editor Execute QueryCtrl+Shift+ESQL.TSqlEditorExecuteQuery
TSql Editor Toggle Results PaneCtrl+D, RSQL.TSqlEditorToggleResultsPane

Windows Forms Designer Shortcuts

For desktop application development, these shortcuts assist in designing user interfaces.

CommandKeyboard ShortcutCommand ID
Move Control DownCtrl+Down ArrowEdit.MoveControlDown
Size Control DownCtrl+Shift+Down ArrowEdit.SizeControlDown
Tab LeftShift+TabEdit.TabLeft

Unleashing the Power of the Visual Studio Code Editor

Beyond shortcuts, the Visual Studio code editor itself is packed with features designed to make writing, managing, and understanding code an intuitive experience. From visual aids to intelligent code generation, these functionalities are key to efficient development.

Core Editor Features

  • Syntax Highlighting: Different elements of your code (keywords, types, strings, comments) are assigned distinct colours. This visual differentiation greatly improves readability and helps in quickly parsing code structure. You can customise these colours via Tools > Options > Environment > Fonts and Colours.
  • Error & Warning Squiggles: As you type, Visual Studio provides instant feedback through coloured squiggly underlines: red for syntax errors, blue for compiler errors, green for warnings, and purple for other issues. These are often accompanied by 'light bulbs' suggesting quick fixes, allowing for immediate problem resolution.
  • Brace Matching & Automatic Surround: When your insertion point is on an opening brace, its corresponding closing brace is highlighted, helping you identify misplaced or missing delimiters. Visual Studio 2022 v17.9+ also automatically surrounds selected text with matching delimiters (e.g., quotes, parentheses) when you type the opening delimiter. This can be toggled in Tools > Options > Text Editor > Display.
  • Structure Visualiser: Dotted lines connect matching braces and other structural elements, making it easier to see the scope of code blocks. This visual aid is invaluable for navigating large codebases.
  • Line Numbers & Change Tracking: Line numbers can be displayed in the left margin for easy reference (enabled in Tools > Options > Text Editor > All Languages). The left margin also tracks changes: yellow for unsaved changes since opening, green for saved changes (before closing), and orange for undone changes after saving.
  • Code & Text Selection (Box Mode): Beyond standard streaming selection, Visual Studio supports 'box mode' selection (hold Alt while dragging or use Alt+Shift+Arrow keys). This allows you to select a rectangular block of text, enabling you to type or paste content at the same point on multiple lines simultaneously.
  • Zoom & Virtual Space: Zoom in or out of any code window by holding Ctrl and using the mouse scroll wheel (or Ctrl+Shift+. to zoom in, Ctrl+Shift+, to zoom out). The zoom percentage can also be set from the status bar. Virtual space allows the cursor to move beyond the end of a line, which can be useful for certain editing tasks, though it cannot be used with Word Wrap simultaneously.
  • Printing Options: The Print dialogue offers options to include line numbers, hide collapsed code regions, and add file paths to headers, providing comprehensive control over your printed code.
  • Global Undo & Redo: Found under the Edit menu, these commands apply to actions that affect multiple files, such as renaming a class across a solution or performing a multi-file find-and-replace. This functionality persists even after closing the solution.

Advanced Editing Capabilities

The Edit > Advanced menu offers a suite of powerful functions to enhance your coding experience.

  • Document & Selection Formatting: Automatically indent lines and format braces for the entire document (Ctrl+K, Ctrl+D) or a selected portion (Ctrl+K, Ctrl+F), ensuring consistent code style.
  • Tabify/Detabify: Convert leading spaces to tabs or tabs to spaces, maintaining coding standards. Commands like Edit.ConvertSpacesToTabs and Edit.ConvertTabsToSpaces can be accessed via the Command Window.
  • Case Conversion (Uppercase/Lowercase): Quickly change the case of selected text or the character at the insertion point (Ctrl+Shift+U for uppercase, Ctrl+U for lowercase).
  • Moving Lines: Easily move selected lines of code up or down (Alt+Up/Down Arrow), useful for reorganising code blocks.
  • Whitespace Management: The 'Show Whitespace' option (Ctrl+R, Ctrl+W) makes spaces visible as dots and tabs as arrows, aiding in identifying and correcting formatting issues. 'Delete Horizontal Whitespace' (Ctrl+K, Ctrl+\) removes trailing spaces.
  • Commenting Code: Quickly comment out (Ctrl+K, Ctrl+C) or uncomment (Ctrl+K, Ctrl+U) selected lines or the current line.
  • Indentation Control: Increase or decrease the indent of selected lines, providing precise control over code block alignment.
  • Tag Selection: In markup files (XML, HTML), select the entire tag or just its content, simplifying editing of structured documents.

Efficient Code Navigation and Search

Navigating large codebases can be daunting, but Visual Studio provides intelligent tools to help you find your way around.

  • Navigation Points: Features like 'Go To' (Ctrl+G to go to a specific line), 'Go To Definition' (F12 or Ctrl+Click on a symbol) to jump to where a type or member is defined, and 'Go To Declaration' (Ctrl+F12) are indispensable for exploring code.
  • Bookmarks: Set bookmarks (Ctrl+K, Ctrl+K) on specific lines of code to quickly return to them later. This is great for marking areas you need to revisit.
  • Finding References: The 'Find All References' command (Shift+F12) shows you every place a particular code element is used within your solution. Additionally, when you select a type or member, all its references in the active file are automatically highlighted.

Smart Code Generation, Correction, and Refactoring

Visual Studio actively assists you in writing better code faster.

  • Code Snippets: Insert pre-defined blocks of code (e.g., a switch statement or an if-else block) with just a few keystrokes (Ctrl+K, Ctrl+X).
  • Quick Actions: The 'light bulb' (Ctrl+.) suggests fixes for errors and warnings, and also offers refactorings and code generation options. This could be generating a new method, introducing a local variable, or simplifying expressions.
  • Refactoring Tools: Beyond simple renaming (Ctrl+R, Ctrl+R), Visual Studio offers powerful refactorings like 'Extract Method' (Ctrl+R, Ctrl+M), 'Encapsulate Field' (Ctrl+R, Ctrl+E), and 'Reorder Parameters' (Ctrl+R, Ctrl+O), which automatically update all references throughout your codebase.
  • Smart Copy & Paste: Visual Studio automatically corrects indentation when you copy code from the IDE and paste it into another application. Furthermore, you can copy JSON or XML text to the clipboard and paste it directly as strongly-typed .NET classes in C# or Visual Basic files using Edit > Paste Special > Paste JSON as Classes (or XML).

Customising Your Visual Studio Environment

Visual Studio allows extensive customisation, from keyboard shortcuts to general settings, which can be shared or reverted as needed.

  • Importing & Exporting Settings: Use the Tools > Import and Export Settings Wizard to save your preferred settings (including keyboard shortcuts, window layouts, and theme preferences) to a file. This file can then be imported onto another machine, shared with colleagues, or used to revert to a previous configuration.
  • Keyboard Shortcut Customisation: As mentioned earlier, the Tools > Options > Environment > Keyboard dialogue is your hub for personalising shortcuts. Take the time to tailor these to your muscle memory for maximum efficiency.

Frequently Asked Questions (FAQs)

How do I find a specific command's keyboard shortcut?
Go to Tools > Options > Environment > Keyboard. In the 'Show commands containing' field, type part of the command's name (e.g., 'build solution'). The assigned shortcut will appear in the 'Shortcut(s) for selected command' box.
Can I change Visual Studio's default shortcuts?
Yes, absolutely. In the Keyboard options dialogue, select the command you wish to change, then enter your desired new shortcut in the 'Press shortcut key(s)' box. Choose the scope (e.g., 'Global' or 'Text Editor') from the 'Use new shortcut in' dropdown, and then click 'Assign'.
What are the main benefits of using keyboard shortcuts?
Keyboard shortcuts significantly boost productivity by reducing mouse reliance, speeding up navigation, and enabling quicker execution of commands. They help maintain flow state, reducing context switching and cognitive load, especially during repetitive tasks.
What are the coloured squiggly lines in the editor, and what do they mean?
These are 'squiggles' that provide real-time feedback on your code. Red indicates a syntax error, blue a compiler error, green a warning, and purple other types of errors or suggestions. They help you catch and fix issues as you code, rather than waiting for compilation.
How can I quickly reformat my entire code document?
To automatically format your entire document according to your configured code style settings, use the shortcut Ctrl+K, Ctrl+D. For just a selected portion of code, use Ctrl+K, Ctrl+F.

Conclusion

Mastering Visual Studio's extensive array of keyboard shortcuts and leveraging its rich editor features is a journey that pays dividends in productivity and coding enjoyment. By integrating these tools into your daily workflow, you'll find yourself navigating, writing, and debugging code with unprecedented speed and precision. Take the time to explore, customise, and practise these functionalities, and watch your development efficiency soar.

If you want to read more articles similar to Mastering Visual Studio: Shortcuts & Editor Tips, you can visit the Automotive category.

Go up