I am doing a lot of C programming this semester, including my own UNIX-inspired OS kernel. I’ve decided to make the move to VIM from emacs and it’s one that no one will regret. Although Vim has an incredible learning curve, the time spent early is fully compensated several times over if you do a decent amount of coding. Vim has so many features and commands that it is impossible to memorize them all. It is a good idea to pick the ones that will save you the most time and just practice. I’ve compiled a growing list of the most useful Vim settings and commands for C programming (which more or less work for any language).
Many of these tips have variations. Follow the links and scan the documentation to find them.
- The * command while on top of a word will move the cursor to the next instance of the same word (if found). The “#” command goes in the other direction. This is a great way to find other uses of a variable.
- The gd command while on top of a variable will move the cursor to the variable’s local declaration.
- If you type CTRL-P while in insert mode, Vim will complete the word with the previous match for words that start with the keyword in front of the cursor.
- The % command will move the cursor to the matching brace, bracket, parentheses, and so on.
- The [[ command will move the cursor to the previous { in the first column (usually the start of a function) while ]] will move to the next } in the first column (end of function).
- Turning on the cindent option will auto indent C code pretty well.
- Turning on the number option will display line numbers.
- The :make command will run the Makefile and move the cursor to the first line with a compile error, if any. This one speeds up the edit-build-debug cycle a lot.
- The command match ErrorMsg /\%>73v.\+/ will highlight all characters past column 73, the standard maximum line width for a text file.






