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.
Ctrl-Y. The same keys work in bash, zsh, and most programs built on readline.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
Worked example: a failing test fixed without touching the mouse
A test fails, and the bug is a price calculation written out by hand in three places in one function. The whole loop, from the run that fails to the commit, stays on the keyboard:
Ctrl `opens the terminal.Ctrl R, typetest, and Enter reruns the last test command. The failure namesapplyDiscountincart.service.ts.⌘P, typecartservand Enter: fuzzy matching finds the file from a few letters.⌘⇧O, typeapplyDand Enter lands on the function.- The function calls
roundMoney().F12on it jumps to the definition to check how it rounds, and⌃-jumps straight back. - The bug:
price * qtyis written out three times and only one copy applies the discount. Select the firstprice * qtywith Shift and the arrow keys, then press⌘Dtwice to add the other two. Three cursors: typelineTotal, thenEscfor a single cursor again. - On the first line that uses it,
⌘⇧Enteropens a new line above. Typeconst lineTotal = price * qty * (1 - discount);.⇧⌥Fformats the file and⌘Ssaves it. Ctrl `back to the terminal,↑and Enter reruns the test. It passes.git commit -am "fix discont on line totals". Spot the typo before Enter:Alt Bfour times to reachdiscont,Alt Dcuts it, typediscount, Enter.
None of these keys is exotic, and each one replaced a scroll, a hunt through the file tree or a reach for the mouse. That is the test for whether a shortcut is worth learning: you do the thing it replaces many times a day.
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.
When to use it, and when not
Learn shortcuts in order of how often you do the thing. For most developers that is: open a file by name (⌘P), search history (Ctrl R), jump to a definition and back (F12, ⌃-), select the next match (⌘D), and edit a command line (Ctrl A, Ctrl E, Ctrl W). Two or three a week, used on purpose until they stick, beats reading this whole sheet.
Use the command palette instead of memorising rare actions. VS Code’s ⌘⇧P shows each command’s shortcut beside it, so you learn the key the third time you search for the same command. ⌘K ⌘S opens the keyboard shortcuts editor to look up or rebind any key.
The mouse still wins for spatial work: dragging a panel, picking a spot you can see in the middle of a long file, resizing, design tools. A shortcut that takes longer to recall than the click it replaces is not worth keeping.
Trade-offs and limits
The same keys mean different things in different layers, and the outermost layer gets them first:
| Key | In the shell | Taken by |
|---|---|---|
Ctrl W | cut the previous word | the browser on Windows and Linux, which closes the tab of a web terminal |
Ctrl R | search history | the browser on Windows and Linux, which reloads the page |
Ctrl A | start of line | GNU screen’s default prefix, and tmux if you moved its prefix there |
Alt B, Alt . | word back, last argument | macOS, which types ∫ and ≥ on a US layout unless Option acts as Meta |
Ctrl S | forward history search | terminal flow control, which freezes output |
Customising fixes conflicts but costs portability. Remapped keys do not exist on a colleague’s machine, a fresh server or a pairing session, so keep the defaults for anything you need everywhere and remap only inside your own editor.
Common mistakes
Ctrl Don an empty prompt. It sends end-of-file, which exits the shell and closes an SSH session. On a line with text it only deletes the character under the cursor.Ctrl Zwhen you meantCtrl C. The program is suspended, not stopped: it still holds its port and open files.jobslists it,fgbrings it back, and bash warns “There are stopped jobs.” when you try to exit.⌘Qinstead of⌘W. One closes a tab or window, the other quits the whole app with every window. Chrome can be set to warn before quitting with⌘Q.- Trusting a hard reload to clear everything.
⌘⇧Rbypasses the cache for that load, but a service worker can still answer requests. With DevTools open, tick “Disable cache” in the Network panel, or right-click the reload button and choose Empty Cache and Hard Reload. - Carrying copy and paste habits into the terminal. On Windows and Linux,
Ctrl Cin a terminal interrupts the running program instead of copying; most Linux terminals copy withCtrl Shift Cand paste withCtrl Shift V.
Check yourself
The bash prompt holds git push origin feature-x with the cursor at the end. What does Ctrl W leave? And Alt Backspace?
Ctrl W leaves git push origin : it cuts back to the previous space, taking all of feature-x. Alt Backspace treats the hyphen as a boundary and cuts only x.
You typed a long command and wiped it with Ctrl U by accident. How do you get it back?
Ctrl Y. Ctrl U, Ctrl K and Ctrl W all save what they cut, and Ctrl Y pastes the most recent cut at the cursor.
Paused on a breakpoint at total = applyDiscount(cart), what is the difference between F10 and F11?
F10 steps over: it runs the whole call and stops on the next line. F11 steps into applyDiscount and stops on its first line.
You suspended Vim with Ctrl Z and type exit in bash. What happens?
Bash refuses once and prints “There are stopped jobs.” Run fg to go back and save. Typing exit again straight away exits anyway and the suspended Vim is killed, with any unsaved changes.
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.