Vim Reboot 6
Command-T
I used Textmate when I first started learning Ruby/Rails and after I switched to Vim, I missed the ability to use the <Cmd>-t hotkey to quickly open up new files. What was so great about it was that you could hit the hotkey and start typing the name of your file to filter the resulting list. Once you had filtered the list enough to have your file appear at the top, you just hit <Enter> and the file would open as the active pane in Textmate.
After a bit of research, I came across Command-T. This plugin works in the exact same and can even be improved with some minor configuration.
Installing this plugin is slightly more involved than others. First, download the .vba, open it in vim and source it with :so %.
You then need to install the C extension:
cd ~/.vim/ruby/command-t
ruby extconf.rb
make
And the plugin will be installed! I would recommend doing the following configuration as well:
From my ~/.vimrc:
" Command-T configuration
" Set the max height to 20 lines
:let g:CommandTMaxHeight=20
" Show dotfiles like .gitignore, .rvmrc
:let g:CommandTAlwaysShowDotFiles=1
" The maximum number of files to search through
:let g:CommandTMaxFiles=20000
" Map ctrl-t to command-T since the meta key isn't available when using
" vim on the server
:map <C-T> :CommandT<CR>
And from my ~/.gvimrc:
" Set the mac meta key
macmenu &File.New\ Tab key=<D-T>
map <D-t> :CommandT<CR>
imap <D-t> <Esc>:CommandT<CR>
When you’re in a project, you can now hit <Cmd>-t and start typing the name of the file you wish to edit. You can scroll up and down the list by using <Ctrl>-j and <Ctrl>-k respectively. To open a file, just hit <Enter>. You can also open a file in a new vertical split by doing <Ctrl>-v, or in a new tab by doing <Ctrl>-t.
Setting the default leader key
It might be a good idea at this point to update the default leader key used to prepend any custom mappings you create. I always set mine to ,.
In ~/.vimrc:
" Set the leader
let mapleader = ","
Now you can do something like this:
" toggle line numbering on and off
map <Leader>n :set number!<CR>
When you hit ,n in vim, line numbers will be toggle on and off.
Command-T’s buffer list
Now that we have the default leader setup, we can take advantage of Command-T’s built-in buffer manager. If you don’t know what buffers are in vim then you should take a look at this page.
After you’ve opened/closed a few files, you hit ,b to see a list of any buffers open in the current session. In some cases, this can actually be quicker than using the standard Command-T interface.
There is an alternative to Command-T’s buffer window called LustyJuggler. I would recommend giving it a try if you’re not fond of how Command-T manages buffers.