Vim Cheat Sheet: All you need to know about Vim keyboard shortcuts

It doesn’t matter if you are an experienced Vim user or a beginner — everyone can benefit from these handy Vim shortcuts that we’ve listed in this article.

Even though there are many graphical rich text editors out there, every Linux user can benefit from using Vim — a command-line based tool that is actually an improved version of venerable vi editor. And that goes for both new Raspberry Pi users and experienced system administrators.

An experienced operator can do wonders with this lightweight editor since it is quite powerful. Apart from providing regular text editing tasks, Vim also supports advanced features. Some of those include find and replace based on encoding conversion and regular expressions, as well as programming features such as code folding and syntax highlighting.

When you are using Vim, if you are in the “command mode” and you press the letter “j”, that will shift the cursor one line down. That happens because the function of a key depends on the mode the editor is in. So in order to make the keys input the character they represent, you’ll have to switch to the “insert mode”.

Now, here’s a list of common Vim shortcuts that will help you use Vim to its full potential.

Vim Shortcuts

Main

  • Escape key — Get out of the mode you’re in and go into the “command mode”. All keys are bound by commands.
  • i — Go into the “insert mode” to insert keys. All keys behave as you would expect.
  • : — Go into “last-line mode” where Vim waits for you to insert a command; for example, to save a document.

Navigation keys

  • h — shift the cursor one character to the left
  • j or Ctrl + J — shift the cursor one line below
  • k or Ctrl + P — shift the cursor one line above
  • I — shift the cursor one character to the right
  • 0 — shift the cursor to the start of the line
  • $ — shift the cursor to the end of the line
  • ^ — shift the cursor to the first character of the line that isn’t empty
  • w — shift one word forward (the following alphanumeric word)
  • W — shift one word forward (delimited by white space)
  • 5w — shift five words forward
  • b — shift one word backward (previous alphanumeric word)
  • B — shift one word backward (delimited by white space)
  • 5b — shift five words backward
  • G — shift to the end of the file
  • gg — shift to the start of the file

Navigating around the document

  • ( — jump back to the previous sentence
  • ) — jump to the following sentence
  • { — jump to the previous paragraph
  • } — jump to the following paragraph
  • [[ — jump to the previous section
  • ]] — jump to the following section
  • [] — jump to the end of the previous section
  • ][ — jump to the end of the following section

Inserting text

  • a — insert text after the cursor
  • A — insert text at the end of the line
  • i — insert text before the cursor
  • o — start a new line under the cursor
  • O — start a new line above the cursor

Special inserts

  • :r [filename] — insert the file [filename] under the cursor
  • :r ![command] — execute [command] and insert its output under the cursor

Deleting text

  • x — delete a character at the cursor
  • dw — delete one word
  • d0 — delete to the start of a line
  • d$ — delete to the end of a line
  • d) — delete to the end of a sentence
  • dgg — delete to the start of the file
  • dG — delete to the end of the file
  • dd — delete one line
  • 3dd — delete three lines

Replacing simple text

  • r{text} — replace the character that’s under the cursor with {text}
  • R — instead of inserting characters, replace them

Copying/Pasting text

  • yy — copy the current line into storage buffer
  • [“x]yy — copy current lines into register x
  • p — paste storage buffer after the current line
  • P — paste storage buffer in front of the current line
  • [“x]p — paste from register x after the current line
  • [“x]P — paste from register x in front of the current line

Undoing/Redoing Operations

  • u — Undo the last operation
  • Ctrl + r — Redo the last undo

Searching and Replacing keys

  • /search_text — search the document for search_text going forward
  • ?search_text — search the document for search_text going backward
  • n — move to the following instance of the result from the search
  • N — move to the previous instance of the result
  • :%s/original/replacement — search for the first incident of the string “original” and replace it with “replacement”
  • :%s/original/replacement/g — search and replace all incidents of the string “original” with “replacement”
  • :%s/original/replacement/gc — search for all incidents of the string “original” but ask for verification before replacing them with “replacement”

Bookmarks

  • m {a-z A-Z} — set bookmarks {a-z A-Z} at the current position of the cursor
  • :marks — list all bookmarks
  • `{a-z A-Z} — jump to the bookmark {a-z A-Z}

Selecting text

  • v — go into the visual mode per character
  • V — go into the visual mode per line
  • Esc — get out of the visual mode

Modifying selected text

  • ~ — switch the case
  • d — delete a word
  • c — change
  • y — yank
  • > — shift right
  • < — shift left
  • ! — filter through an external command

Saving and Quitting

  • :q — quit Vim but not when a file has been changed
  • :w — saves the file
  • :w new_name — save the file with the new_name filename
  • :wq — save the file and quit Vim
  • :q! — quit Vim and don’t save the changes to the file
  • ZZ — write a file, if modified, and then quit Vim
  • ZQ — same as :q!; quit Vim without writing the changes

Have you found these Vim shortcuts helpful? Download the whole list and access it whenever you want!

LEAVE A REPLY

Please enter your comment!
Please enter your name here