VIM Markify

Recently I picked up some minor configs for ruby from Time Pope’s vimrc. Here’s the code :

autocmd FileType ruby
    \ if expand('%') =~# '_test\.rb$' |
    \   compiler rubyunit | setl makeprg=testrb\ \"%:p\" |
    \ elseif expand('%') =~# '_spec\.rb$' |
    \   compiler rspec | setl makeprg=rspec\ \"%:p\" |
    \ else |
    \   compiler ruby | setl makeprg=ruby\ -wc\ \"%:p\" |
    \ endif

What this does is given the filetype is Ruby, it correctly sets up the compiler and makeprg such that it allows you to run your tests via :make! This is pretty neat I must say :), because it correctly loads the quickfix list with the errors and I can actually traverse them in order and fix them. All this without needing any plugin whatsoever :).

Ever since I started using this, I always wanted to mark the lines with errors / warnings with nice signs to highlight lines with errors instantly after I ran :make or :lmake, something similar to what Syntastic does but not just for syntax errors, actual test run errors. As I searched for similar plugins, although I found a bunch of them, I didn’t find them to be very intuitive or simple enough.

Hence I started exploring through vim’s help in an attempt to trying and understanding how I can tap into quickfix & location lists and process them. As it turns out, it’s quite simple and I ended up developing Vim Markify overnight.

I’ve made it quite flexible and it works quite well with all quickfix commands :make, :lmake, :grep, :lgrep, :grepadd, :lgrepadd, :vimgrep, :lvimgrep, :vimgrepadd, :lvimgrepadd, :helpgrep, :lhelpgrep, by tapping into the QuickFixCmdPost autocmd event which triggers right after you run any of the previously mentioned quickfix commands. Although you can choose to disable the autocmd by putting let g:markify_autocmd=0 in your vimrc so that it doesn’t do this automatically and you can trigger :Markify, :MarkifyClear or :MarkifyToggle commands or their corresponding mappings <Leader>mm, <Leader>mc or <Leader>M which can of course be changed. And I was able to achieve all this under 170 sloc :). A lot more things are configurable, I would encourage you to check :h markify.txt within vim or refer to the code at Github

Screenshot:

Image
Vim Markify.
comments powered by Disqus