So, it’s been over a month and a half since I switched back to Vim, and I figured I’d post a bit about how things are going.
I love it. Though the future is notoriously difficult to foretell, I think it’s safe to say that I won’t be switching editors again anytime soon. Vim is where it’s at, for me.
Here’s the combination of plugins and such that I’ve found work best for me.
Any Vim will do, really, but if you’re on a Mac, you really ought to consider MacVim. Like any self-respecting Vim port, it does the command-line really well, but it also has a great OS X GUI interface.
I’ve got my <Leader> character (:h mapleader) mapped to the comma (since it’s easier to reach than the backspace character).
let mapleader = "," |
I’ve installed ack and have configured Vim to use ack for grep.
1 2 |
set grepprg=ack set grepformat=%f:%l:%m |
I’m a believer in spaces instead of tabs (let’s just agree not to go there), and I prefer a tab size of 2. I also like editors to try and guess the indentation level.
1 2 3 4 5 6 |
set tabstop=2 set smarttab set shiftwidth=2 set autoindent set expandtab set backspace=start,indent |
But, some file types really do require explicit tabs, and not spaces:
1 2 |
autocmd FileType make set noexpandtab autocmd FileType python set noexpandtab |
(Update: apparently, python can do tabs or spaces. All my python vimming for the last 8 years has been read-only, so it never actually came up.)
I like my lines numbered, syntax highlighting on, and highlighted searches:
1 2 3 |
set number set hlsearch syntax on |
I’ve got quite a few other things tweaked in my .vimrc, but those are the major biggest ones.
The FuzzyFinder and FuzzyFinder TextMate plugins have become essential for me. For now, installation of the TextMate-like behavior is kind of painful, but I plan to get something up on the Vim scripts index in the nearish future.
My settings for FuzzyFinder TextMate:
1 2 3 4 5 |
let g:fuzzy_ignore = "*.log" let g:fuzzy_matching_limit = 70 map <leader>t :FuzzyFinderTextMate<CR> map <leader>b :FuzzyFinderBuffer<CR> |
Thanks to all who recommended the NERD tree plugin by Marty Grenfell. It really is fantastic, definitely the best-of-breed of VIM project/directory explorers. I especially like that it is easily toggled away. I usually keep it hidden, and toggle it open only when I need to browse to something. (Thanks to the fuzzyfinder stuff, my need for a project browser is pretty small, but when I need one, NERD_tree works great.)
1 |
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR> |
The rails.vim plugin is pretty extensive, and I’m currently only scratching the surface. I don’t use snippets at all (never did in TextMate, either), but the Rake integration is pretty handy, and I’ve used the migration generator pretty often lately.
I need to spend some more time reading the docs for this one, and practicing some of the commands, since I’m sure it could turn into a real time-saver for programmers (like myself) who spend a good part of their day in Rails code.
I’ve really come to love scratch.vim. Sometimes I just need to jot down some numbers, or paste the result of some query, or even take notes on a phone call. Writing any of that on a scrap of paper is a sure way to lose the info. The scratch plugin lets me take notes right where I am all day: in Vim. It doesn’t come with a way to toggle the scratch buffer (which is odd), so I wrote a quick one:
1 2 3 4 5 6 7 8 9 |
function! ToggleScratch()
if expand('%') == g:ScratchBufferName
quit
else
Sscratch
endif
endfunction
map <leader>s :call ToggleScratch()<CR>
|
Maybe it’s just my own coding style, but I find myself commenting and uncommenting large blocks of code on a daily basis. The tComment plugin from Tom Link is perfect for this. You can toggle comments by using the Vim motion operators, or just do a quick visual block followed by “gc”. Good stuff!
There are a few other plugins I’m experimenting with (surround.vim, vcscommand.vim), but which I use infrequently enough that they haven’t become muscle memory yet.
Because I prefer the GUI version of MacVim, I typically have only one or two terminal windows open. I then type “mvim” to open vim from the root of whichever project(s) I’m working on, and then use ”,t” (my FuzzyFinder TextMate trigger) to search for and open files. I also use ”,b” (my FuzzyFinderBuffer trigger) to search my buffer list if I know the file is already open.
Switching between buffers with the carat character ”^” is a huge time saver. I used to use :ls (to list open buffers) and :buffer (to jump to a buffer), but the FuzzyFinderBuffer has really taken the place of both of those.
Ironically, split windows (which I missed most of all when I switched to TextMate) have taken me the longest to fit back into my workflow. TextMate trained them out of me. :) That said, I’m still trying to fit them back in, and when I remember to use them, I love them.
So, that’s me. How does Vim fit in your own workflow? What settings do you prefer, and why? And what customizations are you using in your own setup?