Keyboard Shortcuts (Editor & Terminal)
The muscle-memory keys that make you faster in VS Code, the shell, and the browser devtools — the ones worth memorizing.
Shortcuts pay off when they replace a mouse trip you make dozens of times a day: opening files by name, jumping to a definition, editing several lines at once, recalling a shell command. Learn two or three at a time and use them until they are reflex, rather than trying to memorize the whole sheet.
Keys are macOS defaults: ⌘ Command, ⌥ Option, ⌃ Control, ⇧ Shift. On Windows and Linux, ⌘ is usually Ctrl and ⌥ is Alt. Shell keys work the same on every OS, because bash and zsh share the same Emacs-style line editing.
VS Code (⌘ = Ctrl on Windows/Linux)
- Command palette
⌘⇧P— do anything by name- Quick open file
⌘P— fuzzy file search- Go to symbol / line
⌘⇧O·Ctrl G- Multi-cursor
⌘Dselect next match ·⌥+click to add cursors- Move / copy line
⌥↑/↓move ·⌥⇧↑/↓duplicate- Toggle comment
⌘/- Rename symbol
F2— refactor everywhere- Integrated terminal
Ctrl `- ⌘B / ⌘J
- toggle the sidebar / the bottom panel (terminal, problems, output)
- ⌘⇧F
- search across all files;
⌘⇧Hto replace across them - ⌘T
- go to a symbol anywhere in the workspace, not just this file
- F12 / ⌥F12
- go to definition / peek it inline without leaving the file
- ⇧F12
- every reference to the symbol under the cursor
- ⌃- / ⌃⇧-
- navigate back / forward through where you have been
VS Code: edit & layout
- ⌘⇧L
- select every occurrence of the current selection — one cursor each
- ⌥⌘↑ / ⌥⌘↓
- add a cursor on the line above / below
- ⌘L
- select the current line; press again to extend downward
- ⌃⇧⌘→
- expand the selection to the enclosing word, string, block (
⌃⇧⌘←shrinks) - ⌘⇧K
- delete the whole line, no selection needed
- ⇧⌥F
- format the document with the configured formatter
- ⌘.
- quick fix — imports, lint fixes, refactors under the cursor
- ⌘\
- split the editor;
⌘1/⌘2focus each group - ⌘⇧T
- reopen the editor tab you just closed
Shell (bash/zsh — Emacs mode)
- Start / end of line
Ctrl A/Ctrl E- Delete to end / start
Ctrl K/Ctrl U- Delete word back
Ctrl W- Search history
Ctrl Rthen type;Ctrl Ragain for older- Clear screen
Ctrl L- Cancel / EOF
Ctrl Cinterrupt ·Ctrl DEOF/exit- Suspend / resume
Ctrl Zthenfg- Alt B / Alt F
- back / forward one word — on macOS, Option must be set to act as Meta
- Ctrl Y
- paste back the text the last
Ctrl K,Ctrl UorCtrl Wcut - Alt .
- insert the previous command’s last argument; press again for older ones
- Ctrl X Ctrl E
- edit the line in
$EDITOR; save and quit to run it (zsh needs it bound) - Ctrl _
- undo the last edit on the command line
- sudo !!
- rerun the previous command with sudo;
!$is its last argument - cd -
- jump back to the previous directory
- Ctrl S froze it?
- that is terminal flow control:
Ctrl Qresumes,stty -ixondisables it
Browser devtools
- Open devtools
⌘⌥I/F12- Inspect element
⌘⇧C- Console
⌘⌥J- Command menu
⌘⇧P(inside devtools) — screenshots, throttling, etc.- Hard reload
⌘⇧R— bypass cache- ⌘P (in DevTools)
- open any loaded source file by name
- ⌘⇧M
- device toolbar: phone-sized viewports and touch emulation
- Esc
- toggle the console drawer under whatever panel you are on
- ⌘⌥F
- search across every loaded script and stylesheet
- F8 / F10 / F11
- resume / step over / step into while paused on a breakpoint
- ⌘K
- clear the console
macOS
- ⌘Space
- Spotlight: launch apps, open files, do arithmetic
- ⌘`
- cycle windows of the current app (⌘Tab only switches apps)
- ⌘⇧4
- screenshot a region; Space captures a whole window; add ⌃ to copy it instead of saving
- ⌘⇧5
- screenshot and screen-recording toolbar, with a timer and a save-location menu
- ⌘⌥Esc
- force quit an app that stopped responding
- ⌃⌘Q
- lock the screen
- ⌘⇧.
- show / hide dotfiles in Finder and in open/save dialogs
GitHub (in the browser)
- .
- open the repo or PR in the github.dev web editor
- t
- fuzzy file finder for the repository
- y
- turn the URL into a permalink pinned to the current commit
- b
- blame view of the open file
- ?
- every shortcut available on the current page
Recipes
Rename a variable everywhere, three ways (VS Code)
F2 rename the symbol: language-aware, across files, skips strings and comments
⌘D ⌘D ⌘D select the next occurrences one at a time; ⌘K ⌘D skips the current one
⌘⇧L select every occurrence in the file at once, then type the new name
⌘⇧H find and replace across files for text that is not a symbol (config keys)F2 understands scope, so a same-named variable in another function is left alone; the cursor routes are plain text matching. ⌘U removes the last cursor if you overshoot.
Fix a typo in a long command without retyping it
↑ bring back the last command
Ctrl A jump to the start of the line
Alt F Alt F hop forward two words
Alt D delete the wrong word
Ctrl E jump to the end, then press Enter
# or rewrite it in a real editor:
Ctrl X Ctrl E open the line in $EDITOR; save and quit to run itIn macOS Terminal, tick “Use Option as Meta key” (iTerm2: set Left Option to Esc+), or the Alt keys type symbols instead. In zsh, Ctrl X Ctrl E needs the edit-command-line widget bound first.
Rerun the last command with sudo, or with one fix
apt install ripgrep # Permission denied
sudo !! # runs: sudo apt install ripgrep
cat /etc/nginx/nginx.conf
vim !$ # !$ is the last argument: vim /etc/nginx/nginx.conf
cp config.yml /etc/app/confg.yml
^confg^config # reruns it with the first "confg" replacedBoth shells print the expanded command before running it. Add shopt -s histverify (bash) or setopt HIST_VERIFY (zsh) to review it on the prompt first.
Debug a page from the keyboard (Chrome DevTools)
⌘⌥I open DevTools
⌘⇧C pick the element under the cursor and inspect its styles
Esc open the console drawer below the Elements panel
⌘⇧M device toolbar: test a phone-sized viewport
⌘P open a source file by name, then click a line number for a breakpoint
F8 / F10 resume / step over once paused
⌘⇧P command menu: type "screenshot" to capture the full page or a nodeThe DevTools command menu works like VS Code’s — type “disable JavaScript”, “dark” or “coverage” instead of hunting through panels.
Questions about Keyboard Shortcuts (Editor & Terminal) Cheat Sheet
How do I add multiple cursors in VS Code?
Hold Option on macOS, or Alt on Windows and Linux, and click wherever you want another cursor. Command-Option with the up or down arrow, Ctrl-Alt on Windows, adds a cursor on the line above or below. To edit repeated text, select a word and press Command-D, Ctrl-D on Windows, to add the next occurrence to the selection, or Command-Shift-L to select every occurrence at once. Shift-Option-drag makes a column selection. Press Escape to return to a single cursor, and Command-U to undo only the last cursor you added.
How do I make Option work as Alt or Meta in the macOS terminal?
By default macOS terminals use Option to type special characters, so shortcuts like Alt-B, Alt-F and Alt-. print symbols instead of moving by word. In Terminal, open Settings, then Profiles, then Keyboard, and tick Use Option as Meta key. In iTerm2, open Settings, Profiles, Keys and set the Left Option key to Esc+. Many terminals have a similar option. As a fallback that works everywhere, press Escape and then the letter: Escape followed by B does the same as Alt-B, because Meta is sent as an Escape prefix.
How do I search my command history in the terminal?
Press Ctrl-R and start typing: bash and zsh show the most recent command containing that text. Press Ctrl-R again to step to older matches, Enter to run the match, or the right arrow or Ctrl-E to edit it first. Ctrl-G cancels the search and restores your line. The history command lists past commands with numbers, and an exclamation mark followed by a number reruns one. For fuzzy search across everything you have ever typed, the fzf tool replaces Ctrl-R with an interactive picker, and raising HISTSIZE keeps more history around.
How do I open developer tools in Chrome?
Press Command-Option-I on macOS, or F12 or Ctrl-Shift-I on Windows and Linux. Command-Option-J, or Ctrl-Shift-J, opens straight to the Console, and Command-Shift-C, or Ctrl-Shift-C, opens in element-picking mode so you can click the part of the page you want to inspect. You can also right-click anything on the page and choose Inspect. Once DevTools is open, Command-Shift-P opens its command menu, which finds any panel or setting by name, much like the command palette in VS Code.