Vim tricks from OSCON 2007 and beyond

I stopped by OSCON to attend two tutorials this year. The first was Advanced Vim Scripting, led by Steve Oualline (sitting in for Damian Conway). I was sad to miss The Damian, but Steve is a decent lecturer and boasts endless knowledge of the Vim editor. I enjoyed Steve’s rapid-fire pace and attention to detail. I also grilled him fairly heavily and he aced all my questions.

Lessons learned:

  • additional C syntax highlighting goodies are documented in :help c.vim. For instance, to make trailing whitespace and space before a tab character stand out, add let g:c_space_errors = 1 to your .vimrc
  • using functions and “autocmd FileType” lines is a fine way to customize language-specific settings in your .vimrc
  • type CTRL-W ] on a C symbol name to open up the corresponding declaration in a new window
  • TextMate snippets-like template fill-in is possible using a plugin
  • :vimgrep is cool

I was also inspired to dig into some other C navigation settings. Here’s a quick mini-HOWTO:

  1. install source code tools: sudo yum install cscope ctags (on my Fedora 7 system)
  2. Generate indexes for the current project: ctags -R && cscope-indexer -v -r
  3. in normal mode, "kick the tires":
    1. find references of symbol under cursor: :cscope find s <cword>
    2. find callers of function under cursor: :cscope find c <cword>
    3. find functions called by function under cursor: :cscope find d <cword>
    4. when editing a header, find files which use it: :cscope find i %

I also happened upon Kana's blog, and got more ideas from there (thanks, Kana!):

  • use fold markers to clean up plain text files (see my .vimrc linked at end of post)
  • use 'noequalalways' setting to prevent split window automatic resizing
  • use local function definition and calls to prevent namespace pollution (see my .vimrc)

Other sundries:

My ~/.vimrc

I also attended A Taste of Haskell. In a nutshell: Yikes. Larry Wall said it best: "I think Haskell is easy. I've learned it three times already!"