Editor Shortcuts and Multi Cursor Editing
Multi cursor editing changes what feels possible in a file. These shortcuts are worth the twenty minutes it takes to build the habit.
-
HTML Basics
- What is HTML: The Structure Layer of Every Web Page
- HTML Document Structure: DOCTYPE, html, head and body
- Elements, Tags and Attributes: The Vocabulary of HTML
- HTML Comments: Notes That Ship With Your Code
- Block Level and Inline Elements
- Writing and Running Your First HTML Page
- How a Browser Turns Markup Into a Page
- Text and Formatting
- Links and Navigation
- Images and Media
- Lists
- Tables
-
Forms
- Form Structure: form, action and method
- Input Types: Text, Email, Number, Date and the Rest
- Labels: The Most Important Element in a Form
- Checkboxes, Radio Buttons and Grouping
- select, option, optgroup and datalist
- textarea, File Uploads and Hidden Fields
- Buttons: submit, reset and button
- Built In Form Validation
- GET or POST: What Happens When a Form Is Submitted
- Semantic HTML
- HTML5 Features
- Head and Metadata
- HTML with CSS
- HTML with JavaScript
- Accessibility
-
HTML SEO
- How Google Works: Crawling, Indexing and Ranking
- SEO Friendly HTML Structure
- Titles and Descriptions That Earn Clicks
- Headings and Content Structure for Search
- Internal Linking and Anchor Text
- robots.txt and XML Sitemaps
- Canonical URLs and Duplicate Content
- Structured Data and JSON-LD
- Image SEO
- Core Web Vitals and Mobile Friendliness
- DevTools and Debugging
- Editor Productivity
- HTML Best Practices
- HTML Projects
- Advanced Projects
- Practice and Exams
Concept
Most editing time goes on repetitive changes: renaming a class in nine places, adding an attribute to every list item, reordering lines. Multi cursor editing removes almost all of it.
The shortcuts below are VS Code defaults. Every current editor has equivalents, usually with the same keys.
Multi cursor
| Action | Windows and Linux | macOS |
|---|---|---|
| Add a cursor by clicking | Alt click | Option click |
| Add a cursor above or below | Ctrl Alt arrow | Option Cmd arrow |
| Select the next occurrence | Ctrl D | Cmd D |
| Select every occurrence | Ctrl Shift L | Cmd Shift L |
| Skip this occurrence | Ctrl K then Ctrl D | Cmd K then Cmd D |
| Cursor at the end of every selected line | Shift Alt I | Shift Option I |
| Column selection | Shift Alt drag | Shift Option drag |
| Back to one cursor | Escape | Escape |
Ctrl D is the one to learn first. Put the cursor on a class name, press it repeatedly to select each occurrence, then type once to rename all of them.
Adding an attribute to every list item
<li>Design</li>
<li>Data science</li>
<li>Civil</li>Select the three lines, press Shift Alt I to put a cursor at the end of each, then use Home and arrow keys to reach the right position and type once.
Line editing
| Action | Windows and Linux | macOS |
|---|---|---|
| Move a line up or down | Alt arrow | Option arrow |
| Duplicate a line | Shift Alt arrow | Shift Option arrow |
| Delete a line | Ctrl Shift K | Cmd Shift K |
| Insert a line below | Ctrl Enter | Cmd Enter |
| Insert a line above | Ctrl Shift Enter | Cmd Shift Enter |
| Indent or outdent | Tab / Shift Tab | Same |
| Comment or uncomment | Ctrl / | Cmd / |
| Block comment | Shift Alt A | Shift Option A |
Moving a line with Alt and an arrow reindents it automatically, which makes reordering markup safe.
Selection
| Action | Windows and Linux | macOS |
|---|---|---|
| Expand selection | Shift Alt Right | Ctrl Shift Cmd Right |
| Shrink selection | Shift Alt Left | Ctrl Shift Cmd Left |
| Select a whole line | Ctrl L | Cmd L |
| Select to matching bracket | Ctrl Shift \ | Cmd Shift \ |
| Select everything | Ctrl A | Cmd A |
Expand selection is invaluable in nested markup: press it repeatedly and the selection grows from the word, to the attribute, to the tag, to the whole element.
HTML specific
| Feature | What it does |
|---|---|
| Auto rename tag | Editing an opening tag renames the closing one |
| Auto close tag | Typing > inserts the closing tag |
| Fold and unfold | Ctrl Shift [ and ] |
| Fold everything to a level | Ctrl K then Ctrl 2 |
| Highlight matching tag | Shows the pair of the tag under the cursor |
Folding to level two collapses a long page into its major sections, which makes the structure visible at a glance and is the fastest way to spot a badly nested block.
Navigation
| Action | Windows and Linux | macOS |
|---|---|---|
| Go to file | Ctrl P | Cmd P |
| Command palette | Ctrl Shift P | Cmd Shift P |
| Go to line | Ctrl G | Ctrl G |
| Go to symbol in file | Ctrl Shift O | Cmd Shift O |
| Back and forward | Alt arrow | Ctrl - |
| Switch between open files | Ctrl Tab | Ctrl Tab |
| Split the editor | Ctrl \ | Cmd \ |
Ctrl P takes fuzzy input, so typing ind finds index.html. Once the habit forms, the file explorer becomes almost unnecessary.
Search and replace
| Action | Keys |
|---|---|
| Find in file | Ctrl F |
| Replace in file | Ctrl H |
| Find across the project | Ctrl Shift F |
| Replace across the project | Ctrl Shift H |
| Toggle regular expressions | Alt R inside the find box |
| Toggle case sensitivity | Alt C |
| Toggle whole word | Alt W |
Regular expressions in replace
Find: <img([^>]*)>
Replace: <img$1 loading="lazy">
Find: class="btn (w+)"
Replace: class="button button--$1"
Find: <h3>(.*?)</h3>
Replace: <h2>$1</h2>$1 refers to the first captured group. Always review the matches before replacing across a project - a regular expression that is slightly too greedy can rewrite a great deal in one keystroke.
Two settings worth changing on day one
{
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.tabSize": 2,
"editor.wordWrap": "on",
"editor.linkedEditing": true,
"emmet.triggerExpansionOnTab": true,
"editor.renderWhitespace": "boundary"
}linkedEditing is the one people miss: editing an opening tag name updates the closing tag automatically.
Important rules
Escapealways returns to a single cursor.- Multi cursor edits apply everywhere simultaneously, so mistakes multiply too.
- Project wide replace is not undoable file by file. Review first.
- Format on save keeps a project consistent without anyone thinking about it.
- Shortcuts are rebindable; the defaults are only a starting point.
Common mistakes
- Renaming by hand what
CtrlDwould do in three keystrokes. - Using
CtrlShiftLwithout checking every occurrence should change. - Project wide regular expression replace with no review.
- Never turning on format on save, then arguing about indentation in review.
- Using the mouse to navigate files.
Best practices
- Learn five shortcuts a week rather than all of them at once.
- Use
CtrlDfor renames within a file. - Use
CtrlPinstead of the file tree. - Turn on format on save and linked editing immediately.
- Review every match before a project wide replace.
- Commit before any large mechanical change.
Practice
- Rename a class in twelve places using
CtrlDonly. - Add
loading="lazy"to every image in a file with a regular expression replace. - Fold a long page to level two and describe its structure from the folded view.
- Navigate a project for ten minutes without touching the file explorer.