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, addlet g:c_space_errors = 1to 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
:vimgrepis cool
I was also inspired to dig into some other C navigation settings. Here’s a quick mini-HOWTO:
- install source code tools:
sudo yum install cscope ctags(on my Fedora 7 system) - Generate indexes for the current project:
ctags -R && cscope-indexer -v -r - in normal mode, “kick the tires”:
- find references of symbol under cursor:
:cscope find s <cword> - find callers of function under cursor:
:cscope find c <cword> - find functions called by function under cursor:
:cscope find d <cword> - when editing a header, find files which use it:
:cscope find i %
- find references of symbol under cursor:
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:
- Vim script #453 provides indispensable macros for editing HTML/XHTML
- I’ve also recently been using VimOutliner for all kinds of lists. Thanks Fordor for that tip!
- Next step: omni completion!
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!”