Vim after 11% of my life
February 19, 2013
Right now on Hacker News there is an article Vim after 11 years, detailing the authors current configuration of Vim. I haven’t quite been using it for 11 years (hell, I don’t think I was even programming that long ago…), but I’ve been using it for at least 11% of my life, so close enough. Anyway, this is why I love Vim.
I first started using Vim back when I was in London. I had just started work as a junior developer. I was working in dev ops so I could get to know all the different systems before working on a project. I quite enjoyed it, and it served it’s purpose well. I worked this stint for a bit longer than usual, and during that time the TextMate trial on my machine expired. The two guys I was working with both used Vim, and suggested I do the same. I gave it a go, progress was slow at first, but I made myself stick with it, and eventually here I am today. Writing this in Vim.
Actually I write pretty much everything in Vim. If I can, I use it for everything; Rails, Erlang, blog posts, C, Javascript games. You name it, I probably use Vim. Actually I struggle switching back to an editor that doesn’t use Vim shortcuts. When I was using Linux years ago, I used to curse running commands which interpreted EDITOR
and ran Vim. I used to use Nano whenever I had to edit something. Now it’s the other way around. If nano pops up I have no idea what to do.
I’ve worked with a fair few people who have used Vim. A pretty much equal number who used Emacs (it seems to be the standard with Erlang). Now it seems people are switching to Sublime. One thing I haven’t seen though is other terminal users. Other than when SSHed to a server, everyone seems to use gvim or MacVim. I don’t. My IDE is Tmux + Vim in iTerm2. I love it. I think I can understand why this isn’t the case though. As standard the mouse doesn’t work. Copy and paste doesn’t work. Lots of things you expect to work don’t. But I’ve got used to it, I’ve learnt how it works, and I find myself a lot more productive.
So on to what I’m using, I’ll start with plugins. I try and be fairly ruthless with them. If I’m not using a plugin I rip it out from my .vimrc
. No just in case. If I want to use it I’ll learn the shortcuts, and use it regularly, otherwise it isn’t needed. Obviously syntax highlighting is an exception, as it depends what I’m working on at the time.
Unlike OP, I use Vundle to manage my Vim plugins. If you are thinking the name sounds like Bundler for Ruby, well it’s the same, but for Vim. Vundle stores files the same as Pathogen, execept it also keeps a manifest file of what plugins you have and allows you to update them. I have to admit I have never updated any of the plugins I use, I think there have only been two updates to Vim since I’ve been using it, but anyway…
I also use Vim powerline the same as the OP, so I won’t go into details of that. If you are using Vim in iTerm 2 make sure you install the custom font.
For buffer management I use the interestingly named LustyJugger. By press ,b
I can see a list of my recently active buffers and switched to them by pressing the appropriate key on my home row. E.g. a
for the active tab, b
for the previous, c
for the one before that…. To keep things tidy I also use BufOnly mapped to ,B
which clears all but the current buffer. I don’t use tabs, and haven’t even bothered to look into them. If I need a new session, I open up another instance of Vim in a seperate terminal or Tmux window.
The only other plugin I use is YankRing. I was pairing with a colleague who uses Emacs, and saw them demonstrate the ‘kill ring’ feature, and was like “wow I have to have that in Vim”. Basically it keeps a history of your recently yanked items. Pressing p
as usual pastes the most recently yanked thing. If I then press Ctrl-p
it replaces it with the thing before that, and so on as much as I press Ctrl-p
…
That is it for the plugins (I warned you it would be sparse). I have a few syntax specific things, but that really all I use generally. Other than the plugins, I have a lot of tweaks. I have a lot of stuff in my .vimrc, but I’ll try and cover a few of the important things I like.
From Tmux in iTerm 2 you can copy by pressing alt
and highlighting text. Paste works as usual. In Vim you can do :set paste
to prevent indentation messing things up. I have these two shortcuts instead though:
map <leader>v "*p<CR>:exe ":echo 'pasted from clipboard'"<CR>
map <leader>c "*y<CR>:exe ":echo 'copied to clipboard'"<CR>
Highlight chracters a la TextMate. This shows (evil) tabs and evil trailing whitespace:
set listchars=tab:▸ ,trail:·
Strip all trailing whitespace from a file (useful when you paste code in):
map <leader>s :%s/s+$//e<CR>
When a file is changed externally, auto re-read it rather than prompting (I also have backups and the swap file disabled to prevent errors about that):
set autoread
As annotated really. I love splits, and love resizing them with the mouse:
" enable mouse usage in terminal vim
" (really useful for moving splits!)
set mouse=a
" fix mouse support inside tmux
set ttymouse=xterm2
Tab completion on the command line, similar to zsh:
set wildmode=list:longest
Easier navigation between splits:
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
Other than that, Vim as it is pretty much does all I need. Instead of something such as NERDTree, I use the Vim file browser (<leader>E
). I can create files (%
), rename them (R
) and delete them (D
). I do fall back to !mkdir...
though. I haven’t learnt how to create directories yet, but I should. I have a mentality, that if something needs a lot of key strokes to do, there is probably an easier way built into Vim. So far that has turned out to be pretty true for everything I do.