01-Basic Editing
01-Basic Editing
com/docs/editor/codebasics
(https://vscode.dev/github/microsoft/vscode-docs/blob/main/docs/editor/codebasics.md)
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.
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 ⌥⌘↓ or ⌥⌘↑ that insert cursors below or above.
Note
Your graphics card driver (for example NVIDIA) might overwrite these default shortcuts.
⌘D selects the word at the cursor, or the next occurrence of the current selection.
Tip
You can also add more cursors with ⇧⌘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
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 ,
Shrink/expand selection
Quickly shrink or expand the current selection. Trigger it with ⌃⇧⌘← and ⌃⇧⌘→ .
Place the cursor in one corner and then hold Shift+Alt while dragging to the opposite corner:
Note
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.
You can edit (/docs/getstarted/keybindings) your keybindings.json to bind them to something more
familiar if you want.
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 (/docs/getstarted/settings) and find
the associated settings:
If you want to customize the Auto Save functionality for specific languages or file types, you can do so
"[latex]": { Copy
"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.
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
VS Code allows you to quickly find text and replace in the currently opened file. Press ⌘F to open the
Find Widget in the editor, search results will be highlighted in the editor, overview ruler and minimap.
If there are more than one matched result in the current opened file, you can press Enter and ⇧Enter to
navigate to next or previous result when the find input box is focused.
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
! (vscode://settings/editor.find.history)editor.find.history and
Find In Selection
By default, the find operations are run on the entire file in the editor. It can also be run on selected text.
You can turn this feature on by clicking the hamburger icon on the Find Widget.
If you want it to be the default behavior of the Find Widget, you can set
! (vscode://settings/editor.find.autoFindInSelection)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.
• Match Case
• Match Whole Word
• Regular Expression
The replace input box support case preserving, you can turn it on by clicking the Preserve Case (AB)
button.
While searching long text, the default size of Find Widget might be too small. You can drag the left sash to
enlarge the Find Widget or double click the left sash to maximize it or shrink it to its default size.
VS Code allows you to quickly search over all files in the currently opened folder. Press ⇧⌘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.
Tip
We support regular expression searching in the search box, too.
You can configure advanced search options by clicking the ellipsis (Toggle Search Details) below the
search box on the right (or press ⇧⌘J ). This will show additional fields to configure the search.
Tip
You can use Quick Search to quickly find text across all files in the currently opened folder. Open the
Command Palette ( ⇧⌘P ) and enter the Search: Quick Search command.
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 (/docs/editor/glob-
patterns) syntax, for example:
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 (/docs/getstarted/settings) to change these
rules under the ! (vscode://settings/files.exclude)files.exclude and
! (vscode://settings/search.exclude)search.exclude section.
Note that glob patterns in the Search view work differently than in settings such as
! (vscode://settings/files.exclude)files.exclude and ! (vscode://settings/search.exclude)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
! (vscode://settings/files.exclude)files.exclude and ! (vscode://settings/search.exclude)search.exclude
settings.
Tip
From the Explorer, you can right-click on a folder and select Find in Folder to search inside a folder
only.
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.
Tip
You can quickly reuse a previous search term by using ↓ and ↑ to navigate through your search
term history.
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 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
! (vscode://settings/
search.searchEditor.singleClickBehaviour)search.searchEditor.singleClickBehaviour
and
! (vscode://settings/
search.searchEditor.doubleClickBehaviour)search.searchEditor.doubleClickBehaviour
settings. For example, to open a peek definition window or to open the source location.
You can also use the Open New Search Editor button at the top of the Search view, and can copy your
existing results from a Search view over to a Search Editor with the Open in editor link at the top of the
results tree, or the Search Editor: Open Results in Editor command.
The Search Editor above was opened by selecting the Open New Search Editor button (third button) on
the top of the Search view.
There are two arguments that you can pass to the Search Editor commands
( search.action.openNewEditor , search.action.openNewEditorToSide ) to allow keyboard shortcuts to
configure how a new Search Editor should behave:
• triggerSearch - Whether a search be automatically run when a Search Editor is opened. Default is
true.
• focusResults - Whether to put focus in the results of a search or the query input. Default is true.
For example, the following keyboard shortcut runs the search when the Search Editor is opened but leaves
the focus in the search query control.
{ Copy
"key": "ctrl+o",
"command": "search.action.openNewEditor",
"args": { "query": "VS Code", "triggerSearch": true, "focusResults": false }
}
IntelliSense
We'll always offer word completion, but for the rich languages (/docs/languages/overview), such as
JavaScript, JSON, HTML, CSS, SCSS, Less, C# and TypeScript, we offer a true IntelliSense experience. If a
language service knows possible completions, the IntelliSense suggestions will pop up as you type. You
can always manually trigger it with ⌃Space . By default, Tab or Enter are the accept keyboard triggers
but you can also customize these keyboard shortcuts (/docs/getstarted/keybindings).
Tip
The suggestions filtering supports CamelCase, so you can type the letters which are upper cased in a
method name to limit the suggestions. For example, "cra" will quickly bring up "createApplication".
Tip
IntelliSense suggestions can be configured via the
! (vscode://settings/editor.quickSuggestions)editor.quickSuggestions and
! (vscode://settings/editor.suggestOnTriggerCharacters)editor.suggestOnTriggerCharacters settings
(/docs/getstarted/settings).
JavaScript and TypeScript developers can take advantage of the npmjs (https://www.npmjs.com) type
declaration (typings) file repository to get IntelliSense for common JavaScript libraries (Node.js, React,
Angular). You can find a good explanation on using type declaration files in the JavaScript language (/
docs/languages/javascript#_intellisense) topic and the Node.js (/docs/nodejs/nodejs-tutorial) tutorial.
Formatting
VS Code has great support for source code formatting. The editor has two explicit format actions:
You can invoke these from the Command Palette ( ⇧⌘P ) or the editor context menu.
VS Code has default formatters for JavaScript, TypeScript, JSON, HTML, and CSS. Each language has
specific formatting options (for example,
! (vscode://settings/html.format.indentInnerHtml)html.format.indentInnerHtml ) which you can tune to
your preference in your user or workspace settings (/docs/getstarted/settings). You can also disable the
default language formatter if you have another extension installed that provides formatting for the same
language.
Along with manually invoking code formatting, you can also trigger formatting based on user gestures
such as typing, saving or pasting. These are off by default but you can enable these behaviors through the
following settings (/docs/getstarted/settings):
Note
Not all formatters support format on paste as to do so they must support formatting a selection or
range of text.
In addition to the default formatters, you can find extensions on the Marketplace to support other
languages or formatting tools. There is a Formatters category so you can easily search and find
formatting extensions (https://marketplace.visualstudio.com/search?
target=VSCode&category=Formatters&sortBy=Installs). In the Extensions view search box, type
'formatters' or 'category:formatters' to see a filtered list of extensions within VS Code.
Folding
You can fold regions of source code using the folding icons on the gutter between line numbers and line
start. Move the mouse over the gutter and click to fold and unfold regions. Use Shift + Click on the
folding icon to fold or unfold the region and all regions inside.
Folding regions are by default evaluated based on the indentation of lines. A folding region starts when a
line has a smaller indent than one or more following lines, and ends when there is a line with the same or
smaller indent.
Folding regions can also be computed based on syntax tokens of the editor's configured language. The
following languages already provide syntax aware folding: Markdown, HTML, CSS, LESS, SCSS, and JSON.
If you prefer to switch back to indentation-based folding for one (or all) of the languages above, use:
"[html]": { Copy
"editor.foldingStrategy": "indentation"
},
Regions can also be defined by markers defined by each language. The following languages currently have
markers defined:
C# #region #endregion
Fold selection
The command Create Manual Folding Ranges from Selection ( ⌘K ⌘, ) creates a folding range from the
currently selected lines and collapses it. That range is called a manual folding range that goes on top of
the ranges computed by folding providers.
Manual folding ranges can be removed with the command Remove Manual Folding Ranges ( ⌘K ⌘. ).
Manual folding ranges are especially useful for cases when there isn't programming language support for
folding.
Indentation
VS Code lets you control text indentation and whether you'd like to use spaces or tab stops. By default, VS
Code inserts spaces and uses 4 spaces per Tab key. If you'd like to use another default, you can modify
the ! (vscode://settings/editor.insertSpaces)editor.insertSpaces and
Auto-detection
VS Code analyzes your open file and determines the indentation used in the document. The auto-detected
indentation overrides your default indentation settings. The detected setting is displayed on the right side
of the Status Bar:
You can click on the Status Bar indentation display to bring up a dropdown with indentation commands
allowing you to change the default settings for the open file or convert between tab stops and spaces.
Note
VS Code auto-detection checks for indentations of 2, 4, 6 or 8 spaces. If your file uses a different
number of spaces, the indentation may not be correctly detected. For example, if your convention is
to indent with 3 spaces, you may want to turn off
! (vscode://settings/editor.detectIndentation)editor.detectIndentation and explicitly set the tab
size to 3.
Click on the encoding button in the status bar to reopen or save the active file with a different encoding.
Overtype mode
Prior to release 1.96, VS Code only supported insert mode, where characters are inserted at the cursor
position, unless you installed the Vim keymap extension (/docs/getstarted/keybindings#_keymap-
extensions).
As of release 1.96, VS Code supports overtype mode, which lets you overwrite existing characters instead
of inserting characters at the cursor position. By default, overtype mode is off.
To switch between insert and overtype mode, run the Toggle Overtype/Insert Mode command in the
Command Palette or press ( ⌥⌘O ). When you're in overtype mode, a Status Bar indicator shows OVR .
You can change the cursor style for overtype mode by configuring the
! (vscode://settings/editor.overtypeCursorStyle)editor.overtypeCursorStyle setting.
Compare files
VS Code supports several ways to compare the content of the current file or of any two files.
When you have an active file open in the editor, you have the following compare options:
• Compare with a workspace file: in the Command Palette, select File: Compare Active File With...,
• Right-click on a file in the Explorer view and select Select for Compare. Then, right-click on a
second file and select Compare with Selected.
• To start a comparison between two empty editor windows, select File: Compare New Untitled Text
Files from the Command Palette.
Tip
You can start VS Code from the command line with the --diff option to compare two files. Learn
more about the VS Code command line interface (/docs/editor/command-line#_core-cli-options).
Next steps
You've covered the basic user interface - there is a lot more to VS Code. Read on to find out about:
• Intro Video - Setup and Basics (/docs/introvideos/basics) - Watch a tutorial on the basics of VS
Code.
• User/Workspace Settings (/docs/getstarted/settings) - Learn how to configure VS Code to your
preferences through user and workspace settings.
• Code Navigation (/docs/editor/editingevolved) - Peek and Goto Definition, and more.
• Integrated Terminal (/docs/terminal/basics) - Learn about the integrated terminal for quickly
performing command-line tasks from within VS Code.
• IntelliSense (/docs/editor/intellisense) - VS Code brings smart code completions.
• Debugging (/docs/editor/debugging) - This is where VS Code really shines.
Common questions
You can toggle word wrap for the VS Code session with ⌥Z .
You can also add vertical column rulers to the editor with the
! (vscode://settings/editor.rulers)editor.rulers setting, which takes an array of column character
positions where you'd like vertical rulers.
As in other editors, commands such as Cut and Copy apply to the whole wrapped line. Triple-click selects
the whole wrapped line. Pressing Home twice moves the cursor to the very beginning of the line. Pressing
End twice moves the cursor to the very end of the line.
{ Copy
"key": "shift+alt+down",
"command": "editor.action.insertCursorBelow",
"when": "textInputFocus",
"args": { "logicalLine": true },
},
{
"key": "shift+alt+up",
"command": "editor.action.insertCursorAbove",
"when": "textInputFocus",
"args": { "logicalLine": true },
},
Yes No
02/06/2025
Follow @code(https://go.microsoft.com/fwlink/?LinkID=533687)
Request features(https://go.microsoft.com/fwlink/?LinkID=533482)
Report issues(https://www.github.com/Microsoft/vscode/issues)
Watch videos(https://www.youtube.com/channel/UCs5Y5_7XK8HLDX0SLNwkd3w)
(https://
www.microsoft.com)
(https://go.microsoft.com/fwlink/?LinkID=533687)
(https://github.com/microsoft/vscode) (https://www.youtube.com/@code)
Support (https://support.serviceshub.microsoft.com/supportforbusiness/create?sapId=d66407ed-3967-
b000-4cfb-2c318cad363d)
Privacy (https://go.microsoft.com/fwlink/?LinkId=521839)
Terms of Use (https://www.microsoft.com/legal/terms-of-use) License (/License)