Vim Tips

This is a small collection of tips for the Vim text editor, one of my tools of choice. Hats off to the Vim tips wiki, but I didn’t find these there originally. When I found about most of these, I was in a situation where I figured “there must be a key for that”; sure enough, there was. Other items in this list were added because they seemed useful and I didn’t want to forget about them.

Scroll the viewport
In Normal mode, CTRL+U and CTRL+D scroll half a viewport up and down, respectively. (I don’t know how to do this in Insert mode with the default keybindings–if you do, let me know too!)
Paste in Insert mode
CTRL+R “r, where r is the register to use; a handy one is + for the system clipboard. This also works when entering regular expressions!
Copy the word under the cursor when the cursor is in the middle of the word
yiw in Normal mode (also things like yi“ work to grab quoted text from inside, etc.)
Move the cursor to the top, middle or bottom of the viewport
Normal mode: H, M and L (:help Q_vm)
Display a list of marks
:marks
Execute a shell command and include the results in your document
:r!ls (with ls as an example command)

Also, some help pages are more densely packed with cool tricks than others. Read these:

  • :help Q_ma
  • :help Q_sc

Other helpful posts include Coming Home to Vim.