learn.fttgsolutions.com · Cheat Sheets
Move. Edit. Repeat.
Motions (Horizontal)
| h j k l | h / j / k / l | Move left, down, up, right — the arrow key equivalents. |
| Start of line | 0 | Jump to the very start of the current line. |
| First non-blank | ^ | Jump to the first non-blank character of the current line. |
| End of line | $ | Jump to the end of the current line. |
| Previous word | b | Move backward to the start of the previous word. |
| Next word | w | Move forward to the start of the next word. |
| End of word | e | Move forward to the end of the current or next word. |
| Find character | f{char} | Jump forward to the next occurrence of a character on the line. |
| Find back | F{char} | Jump backward to the previous occurrence of a character on the line. |
Motions (Vertical)
| Half page up/down | Ctrl+u / Ctrl+d | Scroll half a page up or down. |
| Full page up/down | Ctrl+b / Ctrl+f | Scroll a full page up or down. |
| First line | gg | Jump to the first line of the file. |
| Last line | G | Jump to the last line of the file. |
| Go to line n | :n or nG | Jump to line number n. |
| Next empty line | } | Jump to the next blank line (paragraph forward). |
| Previous empty line | { | Jump to the previous blank line (paragraph backward). |
| Screen top/mid/bot | H / M / L | Jump to the top, middle, or bottom line visible on screen. |
| Center current line | zz | Scroll the screen so the current line is centered. |
Insert Mode
| Insert before cursor | i | Enter insert mode before the cursor. |
| Insert after cursor | a | Enter insert mode after the cursor. |
| Insert start of line | I | Enter insert mode at the first non-blank character of the line. |
| Insert end of line | A | Enter insert mode at the end of the current line. |
| New line below | o | Open a new line below the current line and enter insert mode. |
| New line above | O | Open a new line above the current line and enter insert mode. |
| Delete char & insert | s | Delete the character under the cursor and enter insert mode. |
| Delete line & insert | S | Delete the current line and enter insert mode. |
| Change to end of line | C | Delete from cursor to end of line and enter insert mode. |
| Last insert point | gi | Enter insert mode at the position of the last insert. |
| Exit insert mode | Esc or Ctrl+[ | Return to normal mode from insert mode. |
Save & Exit
| Save | :w | Write (save) the current file. |
| Quit | :q | Close the current file (fails if unsaved changes exist). |
| Save and quit | :wq or :x or ZZ | Save the file and quit Vim. |
| Force quit | :q! or ZQ | Quit without saving, discarding all changes. |
| Save and quit all | :wqa | Save all open files and quit Vim. |
| Close all | :qa | Close all open files (fails if any have unsaved changes). |
| Force quit all | :qa! | Force quit all files, discarding all changes. |
| Save to file | :w filename | Write the current buffer to a specific file name. |
| Save as | :sav filename | Save the file under a new name and start editing it. |
| Write readonly file | :w !sudo tee % | Save a file that requires sudo permissions. |
Editing (Normal Mode)
| Replace character | r{char} | Replace the character under the cursor with another character. |
| Replace mode | R | Enter replace mode — typed characters overwrite existing ones. |
| Undo | u | Undo the last change. Prefix with a number to undo multiple times. |
| Undo line | U | Undo all changes made to the current line. |
| Redo | Ctrl+r | Redo the last undone change. |
| Join lines | J | Join the current line with the next line. |
| Repeat last command | . | Repeat the last normal-mode change command. |
Cut, Copy & Paste
| Delete character | x | Delete the character under the cursor (cuts to register). |
| Delete word | dw | Delete from cursor to the start of the next word. |
| Delete line | dd | Delete the entire current line. |
| Delete to end | D | Delete from cursor to the end of the line. |
| Yank (copy) line | yy | Copy the current line into the register. |
| Paste after | p | Paste the register contents after the cursor. |
| Paste before | P | Paste the register contents before the cursor. |
| Swap characters | xp | Transpose (swap) two characters. |
| Swap lines | ddp | Swap the current line with the line below. |
| Yank to clipboard | "+y or "*y | Yank (copy) selected text to the system clipboard. |
| Paste from clipboard | "+p or "*p | Paste from the system clipboard. |
Visual Mode
| Visual mode | v | Enter character-wise visual mode to select text. |
| Visual line mode | V | Enter line-wise visual mode to select whole lines. |
| Visual block mode | Ctrl+v | Enter block (column) visual mode to select a rectangle of text. |
| Select all | ggVG | Select the entire file. |
| Indent selection | > | Shift the selected text one indent level to the right. |
| Outdent selection | < | Shift the selected text one indent level to the left. |
| Delete selection | d or x | Cut the current visual selection. |
| Yank selection | y | Copy the current visual selection. |
Operators
| d — delete | d{motion} | Delete text covered by the motion (e.g. dw, dd, d$). |
| y — yank | y{motion} | Copy text covered by the motion (e.g. yy, yw, y$). |
| c — change | c{motion} | Delete text and enter insert mode (e.g. cw, cc, c$). |
| = — format | ={motion} | Auto-indent code covered by the motion (e.g. gg=G for whole file). |
| gU — uppercase | gU{motion} | Convert text to uppercase (e.g. gUU for current line). |
| gu — lowercase | gu{motion} | Convert text to lowercase (e.g. guu for current line). |
| Count prefix | {n}{operator} | Repeat an operator n times (e.g. 3dd deletes 3 lines, 6yy copies 6). |
Text Objects
| Inner word | iw | Select the word under the cursor, without surrounding spaces. |
| Around word | aw | Select the word under the cursor, including surrounding spaces. |
| Inner quotes | i" or i' | Select text inside the nearest quote pair. |
| Around quotes | a" or a' | Select text including the surrounding quotes. |
| Inner brackets | i( or i[ or i{ | Select text inside the nearest bracket pair. |
| Around brackets | a( or a[ or a{ | Select text including the surrounding bracket pair. |
| Inner paragraph | ip | Select the current paragraph (text block between blank lines). |
| Inner tag | it | Select the content inside an HTML/XML tag. |
| Change inner word | ciw | Delete the word under the cursor and enter insert mode. |
| Change inner quotes | ci" | Delete the content inside quotes and enter insert mode. |
| Delete inner word | diw | Delete the word under the cursor. |
| Delete in quotes | di" | Delete everything inside the nearest quotes. |
Search
| Search forward | /{pattern} | Search forward for a pattern. Press Enter to jump to the first match. |
| Search backward | ?{pattern} | Search backward for a pattern. |
| Next match | n | Jump to the next match in the search direction. |
| Previous match | N | Jump to the previous match. |
| Search current word | * | Search forward for the word under the cursor. |
| Search word back | # | Search backward for the word under the cursor. |
| Case insensitive | /foo\c | Search with case-insensitive matching. |
| Regex search | /\v\d+ | Search using a regular expression (\v enables 'very magic' mode). |
| Clear highlights | :noh | Clear search highlighting without cancelling the search pattern. |
Search & Replace
| Replace first (line) | :s/old/new | Replace the first occurrence of 'old' with 'new' on the current line. |
| Replace all (line) | :s/old/new/g | Replace all occurrences of 'old' on the current line. |
| Replace with confirm | :s/old/new/gc | Replace all on the current line, asking for confirmation each time. |
| Replace first (file) | :%s/old/new | Replace the first occurrence on every line in the file. |
| Replace all (file) | :%s/old/new/g | Replace every occurrence of 'old' with 'new' throughout the file. |
| Replace (confirm) | :%s/old/new/gc | Replace all in file, asking for confirmation at each match. |
| Replace (ignore case) | :%s/old/new/gi | Replace all in file, ignoring case. |
| Replace in range | :2,6s/old/new/g | Replace all occurrences between lines 2 and 6. |
Macros
| Record macro | q{letter} | Start recording a macro into register {letter} (e.g. qa records into 'a'). |
| Stop recording | q | Stop recording the current macro. |
| Run macro | @{letter} | Execute the macro stored in register {letter}. |
| Run macro n times | {n}@{letter} | Execute a macro n times (e.g. 7@a runs macro 'a' seven times). |
| Repeat last macro | @@ | Re-run the most recently executed macro. |
Buffers
| Edit file | :e {file} | Open a file in a new buffer. |
| Next buffer | :bn | Switch to the next buffer. |
| Previous buffer | :bp | Switch to the previous buffer. |
| Delete buffer | :bd | Remove the current file from the buffer list. |
| List buffers | :ls | List all currently open buffers. |
| Go to buffer | :b {file} | Switch to a buffer by file name. |
| Split open | :sp {file} | Open a file in a horizontal split. |
| Vertical split open | :vs {file} | Open a file in a vertical split. |
Windows
| Split horizontal | Ctrl+w s | Split the current window horizontally. |
| Split vertical | Ctrl+w v | Split the current window vertically. |
| Switch window | Ctrl+w w | Cycle focus to the next window. |
| Close window | Ctrl+w q | Close the focused window. |
| Move left/right | Ctrl+w h / Ctrl+w l | Move focus to the window on the left or right. |
| Move up/down | Ctrl+w j / Ctrl+w k | Move focus to the window above or below. |
| Equal size | Ctrl+w = | Make all windows equally sized. |
| Swap windows | Ctrl+w x | Swap the current window with the next one. |
Tabs
| New tab | :tabe {file} | Open a file in a new tab. |
| Close tab | :tabc | Close the current tab. |
| Close other tabs | :tabo | Close all tabs except the current one. |
| List tabs | :tabs | List all open tabs and their windows. |
| Next tab | :tabn or gt | Move to the next tab. |
| Previous tab | :tabp or gT | Move to the previous tab. |
| Go to tab n | {n}gt | Jump directly to tab number n. |
Marks
| Set mark | m{letter} | Mark the current cursor position with a letter (e.g. ma). |
| Jump to mark | `{letter} | Jump to the exact position of mark {letter}. |
| Jump to mark line | '{letter} | Jump to the beginning of the line containing mark {letter}. |
| Last insert position | `^ | Jump to where the cursor was when insert mode was last exited. |
| Last change | `. | Jump to the position of the last change in the current buffer. |
| List marks | :marks | Show all current marks and their positions. |
| Delete mark | :delm {letter} | Delete a specific mark. |
Folds
| Open fold | zo | Open (expand) the fold under the cursor. |
| Close fold | zc | Close (collapse) the fold under the cursor. |
| Toggle fold | za | Toggle the fold under the cursor open or closed. |
| Open all folds | zR | Open every fold in the file. |
| Close all folds | zM | Close every fold in the file. |
Miscellaneous
| Toggle case | ~ | Toggle the case of the character under the cursor. |
| Uppercase word | viw U | Select the current word and convert it to uppercase. |
| Lowercase word | viw u | Select the current word and convert it to lowercase. |
| Increase number | Ctrl+a | Increment the number under the cursor. |
| Decrease number | Ctrl+x | Decrement the number under the cursor. |
| Go back (jump) | Ctrl+o | Jump back to the previous cursor location in the jump list. |
| Go forward (jump) | Ctrl+i | Jump forward in the jump list. |
| Go to file | gf | Open the file whose name is under the cursor. |
| Help | :h {topic} | Open Vim's built-in help for a topic. |
| Reload file | :edit! | Discard changes and reload the current file from disk. |
| Open terminal | :ter | Open a terminal window inside Vim. |
| Sort lines | :sort | Sort all lines in the file (or a selected range) alphabetically. |
| Shell command | :!{cmd} | Execute a shell command without leaving Vim. |
| Insert command output | :r!{cmd} | Insert the output of a shell command into the buffer. |
| Delete lines matching | :g/foo/d | Delete every line in the file that contains the pattern 'foo'. |
| Delete blank lines | :g/^\s*$/d | Remove all blank/whitespace-only lines from the file. |