Visual Studio Code has editing tools that turn ten minutes of repetitive typing into a few keystrokes: several cursors at once, rectangular selections, regex find and replace, and commands that sort or de-duplicate lines. This guide covers the ones worth learning first, with the correct shortcuts for Windows, macOS and Linux in current VS Code.
Learn five things: Ctrl+D (Cmd+D on Mac) to add the next match as a cursor, Ctrl+Shift+L (Cmd+Shift+L) to select every match, Shift+Alt+drag (Shift+Option+drag) for a column selection, Ctrl+H (Option+Cmd+F) for find and replace with regular expressions, and the Command Palette, Ctrl+Shift+P (Cmd+Shift+P), for commands such as Sort Lines and Delete Duplicate Lines. Linux uses the Windows shortcuts except where noted.
1. Multi-cursor editing
Several cursors let you type the same change in many places at once.
| Action | Windows and Linux | macOS |
|---|---|---|
| Add a cursor where you click | Alt+Click | Option+Click |
| Add a cursor above or below | Ctrl+Alt+Up or Down (Linux: Shift+Alt+Up or Down) | Option+Cmd+Up or Down |
| Add a cursor at the end of each selected line | Shift+Alt+I | Shift+Option+I |
| Undo the last cursor you added | Ctrl+U | Cmd+U |
| Back to a single cursor | Escape | Escape |
Once you have several cursors, everything you type, delete or paste happens at each one. Home and End move every cursor to the start or end of its own line, which is ideal for adding a comma or a quote to many lines.
Example: select ten lines of names, press Shift+Alt+I (Shift+Option+I on Mac) to put a cursor at the end of each, and type , to turn them into a list.
If you prefer Ctrl+Click (Cmd+Click) for multi-cursor, change the setting Editor: Multi Cursor Modifier.
2. Select every match: Ctrl+D and Ctrl+Shift+L
This is the fastest way to rename something within one file.
- Put the cursor on a word, or select some text.
- Press Ctrl+D (Cmd+D)to select the next match as well. Press it again for each further match.
- Skip a match you do not wantwith Ctrl+K then Ctrl+D (Cmd+K then Cmd+D), which moves the last selection on to the following match.
- Or select all matches at oncewith Ctrl+Shift+L (Cmd+Shift+L).
- Type the replacement.Every selection changes together.
To delete every occurrence of a word, select them all and press Delete.
For a variable or function name, press F2 instead. Rename Symbol uses the language's understanding of your code, so it changes the real references, across files where the language supports it, and leaves a matching word inside a comment or string alone.
3. Column (box) selection
A column selection is a rectangle of text across several lines, useful for editing aligned data, tables or log lines.
- Mouse: hold Shift+Alt (Shift+Option on Mac) and drag. Dragging with the middle mouse button works too.
- Keyboard: Ctrl+Shift+Alt plus the arrow keys on Windows, or Shift+Option+Cmd plus the arrow keys on Mac. On Linux, look up Column Select in Keyboard Shortcuts (section 8).
- Always on: turn on Selection › Column Selection Mode in the menu, and normal drags make rectangles until you turn it off.
Older guides say Alt+drag makes a column selection. In VS Code, Alt+Click adds cursors; the column drag needs Shift as well.
4. Move, copy and delete lines
| Action | Windows and Linux | macOS |
|---|---|---|
| Move a line up or down | Alt+Up or Down | Option+Up or Down |
| Copy a line up or down | Shift+Alt+Up or Down (Linux: Ctrl+Shift+Alt+Up or Down) | Shift+Option+Up or Down |
| Delete the whole line | Ctrl+Shift+K | Shift+Cmd+K |
| Select the current line | Ctrl+L | Cmd+L |
| Toggle a line comment | Ctrl+/ | Cmd+/ |
| Indent or outdent | Ctrl+] or Ctrl+[ | Cmd+] or Cmd+[ |
All of these work with multiple cursors, so Ctrl+Shift+K with a cursor on five lines deletes all five.
5. Sort, de-duplicate and transform lines
VS Code has built-in commands for line clean-up. Select the lines, open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P) and type the command name:
- Delete Duplicate Lines removes repeated lines and keeps the first copy.
- Sort Lines Ascending and Sort Lines Descending sort alphabetically.
- Transform to Uppercase, Transform to Lowercase and Transform to Title Case change case.
- Join Lines merges the selected lines into one.
- Trim Trailing Whitespace removes spaces at the ends of lines.
To remove duplicates across a whole list, sort first so identical lines sit together, then run Delete Duplicate Lines. Older guides describe a workaround using block comments; it does not remove duplicates, so use this command instead.
6. Find and replace with regular expressions
| Action | Windows and Linux | macOS |
|---|---|---|
| Find in the file | Ctrl+F | Cmd+F |
| Find and replace in the file | Ctrl+H | Option+Cmd+F |
| Select all matches of the search | Alt+Enter | Option+Enter |
| Search across all files | Ctrl+Shift+F | Shift+Cmd+F |
| Replace across all files | Ctrl+Shift+H | Shift+Cmd+H |
The icons in the find box switch on match case, whole word and regular expressions (.*), and the Replace All button next to the replace field changes every match. With regular expressions on, you can reuse parts of the match in the replacement:
- Find
(\w+)@example\.com, replace with[email protected]to change a domain in many addresses while keeping the names. - Find
^\s*$\n, replace with nothing to remove blank lines. - Use
\u$1or\U$1in the replacement to make the captured text start with a capital, or all capitals.
Before a replace across all files, check the preview in the Search view, and make sure your work is committed in Git so you can undo it.
7. Snippets and Emmet
Snippets expand a short prefix into a block of code. Type the prefix, pick the suggestion and press Tab or Enter. To make your own, open the Command Palette, type snippets, choose the Configure Snippets command, then pick a language or a global snippets file.
Emmet is built in for HTML and CSS. Type an abbreviation and accept it from the suggestion list:
div.container>ul>li*5expands to a div with the class container, containing a list with five items. To expand Emmet with the Tab key without waiting for the suggestion, turn on the setting Emmet: Trigger Expansion On Tab.
8. Find any shortcut
You do not need to memorise everything. Open Keyboard Shortcuts with Ctrl+K then Ctrl+S (Cmd+K then Cmd+S) to search every command, see its shortcut on your system and change it. The Command Palette also shows the shortcut next to each command, so using the palette is a good way to learn them.
9. Using VS Code with Domain India hosting
VS Code works well for editing a site on your computer and then publishing it:
- Shared hosting (cPanel, DirectAdmin, Webuzo): upload with FTP (or SFTP once SSH is enabled), or deploy with Git; see deploying with Git. Jailed SSH access is available on every shared hosting plan. It is off by default; ask support to enable it for your account. SSH login uses a key, see generating SSH keys. VS Code's Remote SSH feature installs its own server program in your home folder, and we have not verified that it runs inside the jailed shell, so ask support before relying on it.
- VPS: a Domain India VPS is self-managed with full root access, so Remote SSH and any other tools are yours to set up.
- App Platform: Node.js apps are detected automatically, and other languages deploy with a Dockerfile; see getting started with the App Platform.
- 25 GB NVMe SSD Storage
- 50 GB Monthly Bandwidth
- 1 Website
- 10 Email Accounts
The plan card shows the live Domain India list price, excluding 18% GST.
How do I select multiple lines in VS Code?
Use Shift+Alt and drag with the mouse (Shift+Option on Mac) for a column selection, or put a cursor on each line with Ctrl+Alt+Up or Down (Option+Cmd+Up or Down on Mac). To put a cursor at the end of every selected line, press Shift+Alt+I (Shift+Option+I on Mac).
How do I select all occurrences of a word in VS Code?
Put the cursor on the word and press Ctrl+Shift+L, or Cmd+Shift+L on Mac. To add matches one at a time instead, press Ctrl+D or Cmd+D repeatedly.
How do I remove duplicate lines in VS Code?
Select the lines, open the Command Palette with Ctrl+Shift+P or Cmd+Shift+P, and run Delete Duplicate Lines. Sort the lines first if the duplicates are not next to each other.
How do I delete a whole line in VS Code?
Press Ctrl+Shift+K, or Shift+Cmd+K on Mac. With several cursors, it deletes every line that has a cursor.
What is the replace shortcut in VS Code on Mac?
Option+Cmd+F opens find and replace in the current file, and Shift+Cmd+H replaces across all files.
Can I use VS Code Remote SSH on Domain India shared hosting?
SSH itself is available on request on every shared hosting plan, with key login. Remote SSH also installs a server program in your home folder, which has not been verified inside the jailed shell, so ask support first, or edit locally and upload with FTP or Git.
Ready to put your edits online? Read deploying with Git, set up your SSH key, or ask support to enable jailed SSH on your hosting account.
Git Version Control, FTP, jailed SSH on request and free SSL on every Domain India cPanel plan.
See cPanel hosting plans