Vim is the legendary modal editor that runs everywhere — and in Vim, keyboard keys ARE the interface. This complete list of Vim shortcut keys (commands) explains modes, movement, editing, search and window control in plain words, so a beginner can follow along.
Modes and the Basics
| Key | Function |
|---|---|
| i | Enter Insert mode (before the cursor) |
| a | Enter Insert mode after the cursor (append) |
| I / A | Insert at the start / end of the line |
| o / O | Open a new line below / above and insert |
| Esc (or Ctrl + [) | Return to Normal mode |
| v | Visual mode (select characters) |
| V | Visual Line mode (select whole lines) |
| Ctrl + v | Visual Block mode (rectangular selection) |
| u | Undo |
| Ctrl + r | Redo |
| . (dot) | Repeat the last change |
| :w | Save (write) the file |
| :q | Quit (fails if there are unsaved changes) |
| :wq or ZZ | Save and quit |
| :q! | Quit without saving |
| ZQ | Quit without saving (normal mode) |
| :e filename | Open/edit another file |
Movement Keys
| Key | Function |
|---|---|
| h / j / k / l | Move left / down / up / right |
| w / W | Jump forward to the start of the next word / WORD |
| b / B | Jump back to the start of a word / WORD |
| e / E | Jump to the end of a word / WORD |
| 0 | Go to the first character of the line |
| ^ | Go to the first non-blank character of the line |
| $ | Go to the end of the line |
| g_ | Go to the last non-blank character of the line |
| gg | Go to the first line of the file |
| G | Go to the last line (or {number}G for a specific line) |
| { / } | Move by paragraph (previous / next blank line) |
| ( / ) | Move by sentence |
| % | Jump to the matching bracket ( ) { } [ ] |
| f{char} / F{char} | Find a character forward / backward on the line |
| t{char} / T{char} | Move until just before / after a character |
| ; / , | Repeat the last f/F/t/T jump forward / backward |
| H / M / L | Move to the top / middle / bottom of the screen |
| Ctrl + d / Ctrl + u | Scroll half a page down / up |
| Ctrl + f / Ctrl + b | Scroll a full page forward / back |
| Ctrl + e / Ctrl + y | Scroll one line down / up (cursor stays) |
| zz / zt / zb | Put the current line at the center / top / bottom of the screen |
| * / # | Search for the word under the cursor forward / backward |
| gd | Go to the local declaration of the word under the cursor |
| gf | Open the file whose name is under the cursor |
Editing Keys
| Key | Function |
|---|---|
| x / X | Delete the character under / before the cursor |
| dd | Delete (cut) the whole line |
| dw / d$ (or D) | Delete a word / delete to the end of the line |
| d{motion} | Delete with any motion (e.g. d2w, d}) |
| diw / daw | Delete the inner word / the word including spaces |
| di( / di" / di{ | Delete inside brackets / quotes / braces |
| ciw / ci" | Change (delete + insert) a word / text inside quotes |
| cc / S | Change the whole line |
| C | Change to the end of the line |
| s | Substitute the character (delete + insert) |
| r{char} | Replace the single character under the cursor |
| yy | Yank (copy) the whole line |
| yw / y$ | Yank a word / to the end of the line |
| p / P | Paste after / before the cursor |
| "{a-z}p | Paste from a named register |
| "+y / "+p | Yank / paste using the system clipboard register |
| J | Join the next line to the current one |
| >> / << | Indent / unindent the line |
| == | Auto-indent the line |
| ~ | Toggle the case of the character |
| gu{motion} / gU{motion} | Make the text lower / UPPER case |
| Ctrl + a / Ctrl + x | Increment / decrement the number under the cursor |
| :s/old/new/ | Substitute on the current line (add /g for all matches) |
| :%s/old/new/g | Substitute in the whole file |
Search, Marks, Windows and Extras
| Key | Function |
|---|---|
| /pattern | Search forward |
| ?pattern | Search backward |
| n / N | Next / previous match |
| :noh | Clear the search highlighting |
| m{a-z} | Set a mark at the cursor |
| `{a-z} | Jump to a mark (exact position) |
| '' | Jump back to the previous jump location |
| :marks | List all marks |
| q{a-z} | Record a macro into a register (press q again to stop) |
| @{a-z} / @@ | Play a macro / repeat the last macro |
| :sp / :vsp | Split the window horizontally / vertically |
| Ctrl + w, then h/j/k/l | Move between windows |
| Ctrl + w, then q | Close the current window |
| :tabnew | Open a new tab |
| gt / gT | Next / previous tab |
| :bn / :bp | Next / previous buffer |
| :ls | List open buffers |
| Ctrl + ] / Ctrl + t | Jump to a tag definition / jump back (with ctags) |
| K | Look up the word under the cursor (man page/help) |
| Ctrl + g | Show the file name and position info |
| :set number | Show line numbers (:set nonumber hides them) |
| :help {topic} | Open Vim's built-in help |
Tips for Vim Learners
Vim becomes fast when you think in grammar: verb + number + noun. d (delete) + 2 + w (words) = d2w; c (change) + i + " = rewrite inside quotes. The dot key (.) repeats any change — make one edit, move, press dot. And macros (qa … q, then @a) turn a 100-line cleanup into one recorded sequence. Master hjkl last — the motions above (w, f, %, }) are where the real speed lives.
Frequently Asked Questions
How do I exit Vim?
Press Esc to be in Normal mode, then type :wq and Enter to save and quit, or :q! to quit without saving. ZZ also saves and quits from Normal mode.
How do I copy and paste in Vim?
yy copies the line, p pastes it. For the system clipboard use "+y to copy the selection and "+p to paste (on builds with clipboard support).
How do I replace text in the whole file in Vim?
Use :%s/old/new/g and press Enter — add c (:%s/old/new/gc) to confirm each replacement.
What is the difference between i, a, o in Vim?
i inserts before the cursor, a appends after the cursor, and o opens a brand-new line below (O above) and starts inserting there.
By Umar Farooq, Tech Know.
0 Comments