Here are some tips for a couple of my favorite Vim commands:
Open File Under Cursor
How? Place the cursor over a filename then type gf. Vim attempts to opens the file relative to the current working directory. You can change your current directory using :cd.
Why? I use this command when I am reading error logs to open files mentioned in the log.
Changing Blocks of Text
- cc change the line under the cursor
- ciw change the word under the cursor
- ci" change the contents of the next quote under or after the cursor
- ca" change the entire quote (includes the quote characters)
- ci( change text inside parentheses under the cursor
- ca( includes the enclosing left- and right parentheses characters
- c + motion = change text covered by a motion
Why? I use this family of commands constantly when coding to change string literals or the contents of parenthesis. The list above is incomplete, but you can combine the c-command with any motion you want. For example c3Fx will change text to the third previous occurrence of x.
- zf fold over selected lines
- zo open fold under cursor
- zR open all folds
Why? I mainly use folds together with the latex-suite plugin. Other plugins will also fold text for you. Folds are useful because they reduce the time to manually scan through large blocks of text after a relevant section. If you have large LaTeX documents folds make a big difference by folding all figures etc that would otherwise get in the way of the text!
Increment or Decrement Numbers
<C-a> will make Vim increment the next number on the current line.
<C-x> decrements the number.
Why? Very handy for example when you have a list of indices/offsets and you want to increment all by some amount. I also find that it is often quicker to hit
<C-x> a couple times rather than entering insert mode to adjust a number.