Vim plugins I use

A quick post about some of the vim plugins I use. Since doing all of this I see there is a nice Vim distribution called spf13 that I want to try. It has most of these plugins and a whole lot more, bundled into a nice modern vim distro.


This is a plugin to solve the install of all plugins problem. Typical vim installs require manually copying files into an assortment of plugin/autoload/syntax, etc. directories under ~/.vim. If you extract a file wrong, good luck repairing the damage there. With pathogen, all  you have are plugin roots in your ~/.vim/bundle directory. If you extract incorrectly, just delete  the doc/plugin/syntax directories since they stick out like sore thumbs and retry. It’s nice having a clean ~/.vim. This is all I have in ~/.vim/bundle:

  • ctrlp.vim
  • nerdtree
  • taglist_45
  • vim-fugitive
  • vim-powerline

jdunne recommended pathogen a while back, glad I finally got around to installing it.


Another jdunne recommendation. Lots of cool doo-dads are added to the status line by vim-powerline. Some you may find useful. Here it prettifies by status line:

Each item on the statusline is a called a ‘segment’ and there are plugins that allow you to add segments with arbitrary content. By default, they show your git branch. Eg. BR: upcoming, above.

When I use Control-P, it uses purple for specialized statuslines:

If you run gvim and you want a single configuration, you can add some conditional code for gui/text-only in your vimrc. Here is a sample of what that might look like:

    if has('gui_running')
     set guifont=Monaco:h12
     set transparency=5
     set guioptions=egmrt
     let g:Powerline_symbols = 'fancy'
     let g:Powerline_symbols = 'compatible'


This is a must-gave if you’re a git and vim user. Out of all the plugins I mention here, this is the one that offers the best productivity gains for mw. This blows my mind still:

Bring up the output of git status with :Gstatus. Press - to add/reset a file’s changes, or p to add/reset --patchthat mofo. And guess what :Gcommit does!

You just have to try that. It’s amazing. Show diffs right in the editor with :Gdiff.

:Gmove does a git mv on a file and simultaneously renames the buffer. :Gremove does a git rm on a file and simultaneously deletes the buffer

Oh just go and install it already.

My entire dotfiles setup is over at my github account:

VIM and tabs and simplicity

I use vim at work for all of my coding. I recently tried to abandon NERDtree in favor of CtrlP, coaxed by a co-worker who did the same. This is an abandonment of a directory tree to find my files in favor of using fuzzy search to find the filename. After I made this switch, I felt like I needed tabs. They didn’t seem necessary when I had a directory tree there, but now I feel like I need the tabs so I can switch back for forth between files more easily. I guess I didn’t mind clicking multiple times, but I mind typing file names multiple times.

I also program mostly in grails these days, developing a web application that monitors some of our services. In grails, filenames are named in a very specific way so repeat file names are not common. Therefore, the default tab name in vim, whose path is cleverly compressed, is still too verbose for me. E.g.:

" Tab formatting
function MyTabLabel(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
let file = bufname(buflist[winnr - 1])
return fnamemodify(file, ':p:t')

function MyTabLine()
let s = ''
for i in range(tabpagenr('$'))
" select the highlighting

if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
let s .= '%#TabLine#'

" set the tab page number (for mouse clicks)
let s .= '%' . (i + 1) . 'T'

" the label is made by MyTabLabel()
let s .= ' %{MyTabLabel(' . (i + 1) . ')} '

" after the last tab fill with TabLineFill and reset tab page nr
let s .= '%#TabLineFill#%T'

" right-align the label to close the current tab page
if tabpagenr('$') > 1
let s .= '%=%#TabLine#%999Xclose'

return s

:set tabline=%!MyTabLine()

I found most of that in the docs, but this line I wrote to just pull the base filename:

    let file = bufname(buflist[winnr - 1])
    return fnamemodify(file, ':p:t')

I wish there were a simpler solution, but for now this works.

vim and markdown editing

I struggled with vim a bit tonight. I wanted to set it up to edit markdown files and have it behave like a word processor, where at a certain point on a line the text would automatically wrap. After googling for, well, hours, I found out that vim is not a word processor and word wrap simply isn’t in its genes.

Well, kind of.

The first thing I did was install the markdown file type plugin. There are a few and I think I like this one the best: Not sure why, it just seems to do the most stuff.

Then I set a few options in .vimrc, specific to markdown filetypes:

autocmd Filetype markdown setlocal wrap
autocmd Filetype markdown setlocal linebreak
autocmd Filetype markdown setlocal nolist
autocmd Filetype markdown setlocal columns=80

The columns=80 actually sets the width of the vim application to 80 columns, which sets he size of the terminal window to 80-columns on my Mac’s iTerm. This is a bit annoying. What I really wanted was for vim to be wide, like the terminal, but for the text to wrap at 80 characters.


Alternatively, if I could live with line breaks, I could set up vim so hitting gq would force a paragraph to wordwrap, or gggqG to format the entire document. That config looks like this:

autocmd Filetype markdown setlocal tw=80
autocmd Filetype markdown setlocal wm=4
autocmd Filetype markdown setlocal fo=cat

But I can’t live with line breaks. This markdown editing is what I do all of my writing in…, it’s simple. I can strip it out if necessary, or I could go the other way and generate html, pdf’s, etc. More on that in another post.