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 (
- Display a list of marks
- Execute a shell command and include the results in your document
lsas an example command)
- Automatic code reformatting
=character works great for C-like languages
- Rebuild help tags
- Pathogen provides
:Helptagsto rebuild the help tag database
- Surround an object with quotes
vim-surroundplugin provides e.g. ysiw" to surround a word under the cursor with double quotes.
Also, some help pages are more densely packed with cool tricks than others. Read these: