Basic editing
Visual Studio Code is an editor first and foremost, and includes the features you need for highly productive source code editing. This topic takes you through the basics of the editor and helps you get moving with your code.
Keyboard shortcuts
Being able to keep your hands on the keyboard when writing code is crucial for high productivity. VS Code has a rich set of default keyboard shortcuts as well as allowing you to customize them.
- Keyboard Shortcuts Reference - Learn the most commonly used and popular keyboard shortcuts by downloading the reference sheet.
- Install a Keymap extension - Use the keyboard shortcuts of your old editor (such as Sublime Text, Atom, and Vim) in VS Code by installing a Keymap extension.
- Customize Keyboard Shortcuts - Change the default keyboard shortcuts to fit your style.
Multiple selections (multi-cursor)
VS Code supports multiple cursors for fast, simultaneous edits. You can add secondary cursors (rendered thinner) with Alt+Click. Each cursor operates independently based on the context it sits in. A common way to add more cursors is with β₯ββ (Windows Ctrl+Alt+Down, Linux Shift+Alt+Down) or β₯ββ (Windows Ctrl+Alt+Up, Linux Shift+Alt+Up) that insert cursors below or above.
Your graphics card driver (for example NVIDIA) might overwrite these default shortcuts.
βD (Windows, Linux Ctrl+D) selects the word at the cursor, or the next occurrence of the current selection.
You can skip the next matching occurrence while using multi-cursor find by running βK βD (Windows, Linux Ctrl+K Ctrl+D). This helps you avoid adding unwanted selections when editing repeated text.
You can also add more cursors with β§βL (Windows, Linux Ctrl+Shift+L), which will add a selection at each occurrence of the current selected text.
Multi-cursor modifier
If you'd like to change the modifier key for applying multiple cursors to Cmd+Click on macOS and Ctrl+Click on Windows and Linux, you can do so with the editor.multiCursorModifier setting. This lets users coming from other editors such as Sublime Text or Atom continue to use the keyboard modifier they are familiar with.
The setting can be set to:
ctrlCmd- Maps to Ctrl on Windows and Cmd on macOS.alt- The existing default Alt.
There's also a menu item Selection > Switch to Ctrl+Click for Multi-Cursor or Selection > Switch to Alt+Click for Multi-Cursor to quickly toggle this setting.
The Go to Definition and Open Link gestures will also respect this setting and adapt such that they do not conflict. For example, when the setting is ctrlCmd, multiple cursors can be added with Ctrl/Cmd+Click, and opening links or going to definition can be invoked with Alt+Click.
Shrink/expand selection
Quickly shrink or expand the current selection. Trigger it with ββ§ββ (Windows, Linux Shift+Alt+Left) and ββ§ββ (Windows, Linux Shift+Alt+Right).
Here's an example of expanding the selection with ββ§ββ (Windows, Linux Shift+Alt+Right):
Column (box) selection
Place the cursor in one corner and then hold Shift+Alt while dragging to the opposite corner:
This changes to Shift+Ctrl/Cmd when using Ctrl/Cmd as multi-cursor modifier.
There are also default keyboard shortcuts for column selection on macOS and Windows, but not on Linux.
| Key | Command | Command ID |
|---|---|---|
| β§β (Windows, Linux Shift+Down) | Column Select Down | cursorColumnSelectDown |
| β§β (Windows, Linux Shift+Up) | Column Select Up | cursorColumnSelectUp |
| β§β (Windows, Linux Shift+Left) | Column Select Left | cursorColumnSelectLeft |
| β§β (Windows, Linux Shift+Right) | Column Select Right | cursorColumnSelectRight |
| β§PageDown (Windows, Linux Shift+PageDown) | Column Select Page Down | cursorColumnSelectPageDown |
| β§PageUp (Windows, Linux Shift+PageUp) | Column Select Page Up | cursorColumnSelectPageUp |
You can edit your keybindings.json to bind them to something more familiar if you want.
Paste a column selection
When you copy a column selection and paste it at a single cursor, the default spread value of
editor.multiCursorPaste
inserts each copied row on a successive line at the same visible column. To preserve the column, the editor pads shorter destination lines or copied rows with ordinary spaces as needed.
In this example, the copied rows are A, B, and C, and | represents the cursor:
Before After
abc| abcA
x x B
123456 123C456
Set
editor.multiCursorPaste
to full to paste the copied text as normal multiline text at one destination.
When you paste at multiple cursors, rows are distributed in document order if the number of copied rows matches the number of cursors. Otherwise, the full copied text is pasted at each cursor.
Column Selection mode
The user setting Editor: Column Selection controls this feature. Once this mode is entered, as indicated in the Status bar, the mouse gestures and the arrow keys will create a column selection by default. This global toggle is also accessible via the Selection > Column Selection Mode menu item. In addition, one can also disable Column Selection mode from the Status bar.
Auto-closing brackets
When you type an opening bracket, VS Code can insert the matching closing bracket based on the active language configuration. The editor.autoClosingBrackets setting controls this behavior:
languageDefined: Use the language configuration to determine when to insert a closing bracket. This value is the default.beforeWhitespace: Insert a closing bracket only when the cursor is before whitespace.always: Always insert a closing bracket.never: Do not insert a closing bracket.
For the languageDefined and beforeWhitespace values, if a matching unpaired closing bracket exists later in the document, VS Code does not insert a duplicate. Set
editor.autoClosingBrackets
to always to insert a closing bracket even when an unpaired closing bracket already exists.
Bracket balancing depends on token-aware bracket information. Until tokenization is complete, or for files too large for bracket-pair analysis, the editor uses its standard auto-closing behavior. With multiple cursors, if any cursor can pair with an unpaired closing bracket, the editor suppresses auto-closing at every cursor.
Auto-closing for quotes is controlled separately by the editor.autoClosingQuotes setting.
Save / Auto Save
By default, VS Code requires an explicit action to save your changes to disk, βS (Windows, Linux Ctrl+S).
When an editor has unsaved changes, a dot indicator is displayed in the editor tab, and the Explorer view shows a badge indicating the number of unsaved files. These changes are not yet saved to disk, but VS Code automatically backs them up so they can be restored if the application closes unexpectedly (see Hot Exit).
However, it's easy to turn on Auto Save, which will save your changes after a configured delay or when focus leaves the editor. With this option turned on, there is no need to explicitly save the file. The easiest way to turn on Auto Save is with the File > Auto Save toggle that turns on and off save after a delay.
For more control over Auto Save, open User or Workspace settings and find the associated settings:
-
files.autoSave
: Can have the values:
off- to disable auto save.afterDelay- to save files after a configured delay (default 1000 ms).onFocusChange- to save files when focus moves out of the editor of the dirty file.onWindowChange- to save files when the focus moves out of the VS Code window.
-
files.autoSaveDelay
: Configures the delay in milliseconds when
files.autoSave
is configured to
afterDelay. The default is 1000 ms.
If you want to customize the Auto Save functionality for specific languages or file types, you can do so from the settings.json file by adding language-specific rules.
For example, to disable Auto Save for LaTeX files:
"[latex]": {
"files.autoSave": "off",
},
Hot Exit
By default, VS Code remembers unsaved changes to files when you exit. Hot exit is triggered when the application is closed via File > Exit (Code > Quit on macOS) or when the last window is closed.
You can configure hot exit by setting files.hotExit to the following values:
"off": Disable hot exit."onExit": Hot exit will be triggered when the application is closed, that is when the last window is closed on Windows/Linux or when theworkbench.action.quitcommand is triggered (from the Command Palette, keyboard shortcut or menu). All windows without folders opened will be restored upon next launch."onExitAndWindowClose": Hot exit will be triggered when the application is closed, that is when the last window is closed on Windows/Linux or when theworkbench.action.quitcommand is triggered (from the Command Palette, keyboard shortcut or menu), and also for any window with a folder opened regardless of whether it is the last window. All windows without folders opened will be restored upon next launch. To restore folder windows as they were before shutdown, set window.restoreWindows toall.
If something goes wrong with hot exit, all backups are stored in the following folders for standard install locations:
- Windows
%APPDATA%\Code\Backups - macOS
$HOME/Library/Application Support/Code/Backups - Linux
$HOME/.config/Code/Backups
Find and replace
VS Code allows you to quickly find and replace text in the currently opened file. Press βF (Windows, Linux Ctrl+F) to open the Find control in the editor and type the search string. The search results are highlighted in the editor, overview ruler, and minimap.
VS Code immediately starts searching as you type. To only start searching when you press Enter, clear the editor.find.findOnType setting.
To automatically close the Find control after a match is found and return focus to the editor, enable the editor.find.closeOnResult setting.
If there are multiple matches in the current file, press Enter to go to the next result or β§Enter (Windows, Linux Shift+Enter) to go to the previous result while the find input box has focus.
By default, VS Code saves the history of your find and replace queries for a workspace and restores it across restarts. You can configure this behavior with the
editor.find.history
and
editor.find.replaceHistory
settings. Set the value to never to disable saving the history.
Seed search string from selection
When the Find control is opened, it will automatically populate the selected text in the editor into the find input box. If the selection is empty, the word under the cursor will be inserted into the input box instead.
This feature can be turned off by setting
editor.find.seedSearchStringFromSelection
to "never".
Find in selection
By default, the find operations are run on the entire file in the editor. To limit the search to the text selection, select the Find in Selection icon on the Find control or press β₯βL (Windows, Linux Alt+L).
If you want it to be the default behavior of the Find control, you can set
editor.find.autoFindInSelection
to always, or to multiline, if you want it to be run on selected text only when multiple lines of content are selected.
Advanced find and replace options
For more advanced scenarios, the Find and Replace control has the following options:
-
Find control:
- Match Case
- Match Whole Word
- Regular Expression
-
Replace control:
- Preserve case

Multiline support and Find control resizing
You can search multiple line text by pasting the text into the Find input box and Replace input box. Pressing Ctrl+Enter inserts a new line in the input box.
While searching long text, the default size of Find control might be too small. You can drag the left sash to enlarge the Find control or double click the left sash to maximize it or shrink it to its default size.
Search across files
VS Code allows you to quickly search over all files in the currently opened folder. Press β§βF (Windows, Linux Ctrl+Shift+F) and enter your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location. Expand a file to see a preview of all of the hits within that file. Then single-click on one of the hits to view it in the editor.

VS Code also supports regular expression searching in the search box.
You can configure advanced search options by selecting the ellipsis (Toggle Search Details) below the search box on the right (or press β§βJ (Windows, Linux Ctrl+Shift+J)). This shows additional fields to configure the search.
You can use Quick Search to quickly find text across all files in the currently opened folder. Open the Command Palette (β§βP (Windows, Linux Ctrl+Shift+P)) and enter the Search: Quick Search command.
Advanced search options

In the two input boxes below the search box, you can enter patterns to include or exclude from the search. If you enter example, that will match every folder and file named example in the workspace. If you enter ./example, that will match the folder example/ at the top level of your workspace. Use , to separate multiple patterns. Paths must use forward slashes. You can also use glob pattern syntax, for example:
*to match zero or more characters in a path segment?to match on one character in a path segment**to match any number of path segments, including none{}to group conditions (for example{**/*.html,**/*.txt}matches all HTML and text files)[]to declare a range of characters to match (example.[0-9]to match onexample.0,example.1, β¦)[!...]to negate a range of characters to match (example.[!0-9]to match onexample.a,example.b, but notexample.0)
Note about case sensitivity: Glob patterns follow your operating system's file system rules. On Windows and macOS, patterns are case-insensitive (for example, *.CS matches file.cs). On Linux, patterns are case-sensitive. This is separate from the search text Match Case toggle, which controls whether the search text itself is case-sensitive. Learn more about glob patterns.
VS Code excludes some folders by default to reduce the number of search results that you are not interested in (for example: node_modules). Open settings to change these rules under the
files.exclude
and
search.exclude
section.
Note that glob patterns in the Search view work differently than in settings such as
files.exclude
and
search.exclude
. In the settings, you must use **/example to match a folder named example in subfolder folder1/example in your workspace. In the Search view, the ** prefix is assumed. The glob patterns in these settings are always evaluated relative to the path of the workspace folder.
Also note the Use Exclude Settings and Ignore Files toggle button in the files to exclude box. The toggle determines whether to exclude files that are ignored by your .gitignore files and/or matched by your
files.exclude
and
search.exclude
settings.
In the files to include box, you can use the Search only in changed files toggle button to restrict search results to files that have uncommitted source control changes. This toggle is disabled when there's no repository or no changes to search.
Patterns in .gitignore files are matched case-insensitively on Windows and macOS, and case-sensitively on Linux. Learn more about glob pattern case sensitivity.
From the Explorer, you can right-click on a folder and select Find in Folder to search inside a folder only.
Search and replace
You can also Search and Replace across files. Expand the Search widget to display the Replace text box.

When you type text into the Replace text box, you will see a diff display of the pending changes. You can replace across all files from the Replace text box, replace all in one file or replace a single change.

You can quickly reuse a previous search term by using β (Windows, Linux Down) and β (Windows, Linux Up) to navigate through your search term history.
Case changing in regex replace
VS Code supports changing the case of regex matching groups while doing Search and Replace in the editor or globally. This is done with the modifiers \u\U\l\L, where \u and \l will upper/lowercase a single character, and \U and \L will upper/lowercase the rest of the matching group.
Example:
The modifiers can also be stacked - for example, \u\u\u$1 will uppercase the first three characters of the group, or \l\U$1 will lowercase the first character, and uppercase the rest. The capture group is referenced by $n in the replacement string, where n is the order of the capture group.
Search Editor
Search Editors let you view workspace search results in a full-sized editor, complete with syntax highlighting and optional lines of surrounding context.
Below is a search for the word 'SearchEditor' with two lines of text before and after the match for context:

The Open Search Editor command opens an existing Search Editor if one exists, or to otherwise create a new one. The New Search Editor command will always create a new Search Editor.
In the Search Editor, results can be navigated to using Go to Definition actions, such as F12 to open the source location in the current editor group, or βK F12 (Windows, Linux Ctrl+K F12) to open the location in an editor to the side. Additionally, you can configure the behavior for single-clicking or double-clicking a search result with the search.searchEditor.singleClickBehaviour and search.searchEditor.doubleClickBehaviour settings. For example, to open a peek definition window or to open the source location.
You can also use the