Tool cheatsheet
Vim 9 Cheatsheet
Keystrokes for exiting, moving, editing, searching and working with files in Vim, including how to quit it.
Saving and quitting
- Save the file — Write the buffer to disk and stay in Vim.
- Save and quit — Write the file and exit Vim.
- Quit — Exit Vim. It refuses if there are unsaved changes.
- Quit without saving — Exit and throw away all unsaved changes.
- Save and quit from normal mode — Write only if changed and exit, without typing a command.
- Save all files and quit — Write every modified buffer and exit.
- Save a file you opened without sudo — Write a root-owned file through sudo and tee after forgetting to open it with sudo.
Modes
- Insert before the cursor — Start typing at the cursor position.
- Insert after the cursor — Start typing after the cursor.
- Append at the end of the line — Move to the end of the line and start typing.
- Insert at the start of the line — Move to the first non-blank character and start typing.
- Open a new line below — Add an empty line under the current one and start typing.
- Open a new line above — Add an empty line over the current one and start typing.
- Return to normal mode — Leave insert or visual mode. Ctrl-[ does the same.
Moving around
- Move by character and line — Left, down, up, right. Prefix a count to repeat, such as 5j.
- Move by word — Forward to the next word start, back to the previous word start, or to the end of the word.
- Jump within a line — Start of line, first non-blank character, and end of line.
- Jump to the start or end of the file — Go to the first line or the last line.
- Go to a line number — Jump to line 42 of the file.
- Scroll by page — Scroll down or up a full page.
- Move by paragraph — Jump to the next or previous blank line.
- Jump to the matching bracket — Move between a bracket and its partner.
- Jump back to where you were — Move back and forward through the jump list.
Editing text
- Delete a character — Delete the character under the cursor.
- Delete a line — Delete the current line into the register. Prefix a count to delete several.
- Delete a word — Delete from the cursor to the start of the next word.
- Delete to the end of the line — Delete from the cursor to the end of the line.
- Change a word — Delete the word under the cursor and start typing.
- Change text inside quotes — Replace everything between the surrounding double quotes.
- Replace a whole line — Delete the line's contents and start typing.
- Replace one character — Replace the character under the cursor with another.
- Join lines — Join the current line with the next one.
- Indent or unindent a line — Shift the line right or left by one shiftwidth.
- Re-indent the whole file — Auto-indent from the first line to the last.
- Repeat the last change — Repeat the last editing command at the cursor.
- Increment a number — Add one to the number under or after the cursor. Ctrl-x subtracts one.
Copy, paste and undo
- Copy a line — Copy the current line into the register.
- Copy a word — Copy from the cursor to the start of the next word.
- Paste after or before — Paste the register after the cursor (or below a line), or before it with a capital P.
- Undo — Undo the last change. Prefix a count to undo several.
- Redo — Redo a change you just undid.
- Copy to the system clipboard — Copy the current line to the system clipboard. Needs Vim built with clipboard support.
- Paste from the system clipboard — Paste the system clipboard after the cursor.
- Show registers — List the contents of all registers.
Searching and replacing
- Search forward — Search for text below the cursor. Press n for the next match and N for the previous one.
- Search backward — Search for text above the cursor.
- Search for the word under the cursor — Jump to the next occurrence of the word under the cursor.
- Replace in the whole file — Replace every occurrence of old with new.
- Replace with confirmation — Ask before each replacement.
- Replace in a selection — After selecting lines in visual mode, replace only inside them. Vim fills in the range.
- Clear search highlighting — Turn off the highlight until the next search.
- Delete all lines matching a pattern — Delete every line that contains the pattern.
- Ignore case unless you type capitals — Make searches case-insensitive unless the pattern has an uppercase letter.
Visual mode
- Select characters — Start selecting by character. Move to extend the selection.
- Select whole lines — Start selecting whole lines.
- Select a block — Start a rectangular selection.
- Select a paragraph — Select the paragraph around the cursor.
- Insert text on several lines — Select a block down several lines, press I, type, then Esc to apply it to every line.
- Reselect the last selection — Select the same text again.
Files, buffers and windows
- Open a file — Open another file in the current window.
- List open buffers — Show buffers and their numbers.
- Switch buffers — Go to the next or previous buffer, or to buffer 2 by number.
- Close the current buffer — Remove the buffer from the list.
- Split the window horizontally — Show the same or another file in a new window above.
- Split the window vertically — Open a file in a new window beside the current one.
- Move between windows — Move to the window on the left, below, above or right.
- Open a new tab — Open a tab page. Switch with gt and gT.
- Browse files — Open the built-in file explorer in the current window.
Macros and settings
- Record a macro — Record keystrokes into register a. Press q again to stop recording.
- Play a macro — Run register a. Prefix a count to repeat it, such as 10@a.
- Repeat the last macro — Run the most recently used macro again.
- Show line numbers — Show the line number beside each line.
- Show relative line numbers — Show distances from the cursor line, which helps with motions like 5j.
- Use four spaces for indentation — Insert spaces when you press Tab.
- Paste without auto-indent — Stop Vim re-indenting pasted text. Turn it off again with :set nopaste.
- Run a shell command — Run a command and show its output.
- Insert a command's output — Read the output of a command into the buffer below the cursor.
- Open help — Open the built-in help for a topic.
Related cheatsheets
- Ansible 2 cheatsheet — Run ad-hoc commands and playbooks, manage inventories, roles, collections and secrets with Ansible.
- Argo CD 3 cheatsheet — Install Argo CD, define Applications declaratively, and manage sync, diffs, history and rollbacks with the argocd CLI.
- AWS CLI 2 cheatsheet — Configure credentials and manage S3, EC2, Lambda, logs, containers and secrets with the AWS CLI v2.
- Azure CLI 2 cheatsheet — Sign in and manage resource groups, VMs, web apps, storage, Kubernetes, registries and secrets with the az command.
- Bash and Linux 5 cheatsheet — Everyday shell and Linux commands for files, searching text, permissions, processes and servers.
- Claude API cheatsheet — Call Claude from Python, TypeScript or curl: messages, streaming, thinking, tools, structured output, caching, batches and error handling.