Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (42 sloc) 1.79 KB

Vim coverage for Simplecov

This is a formatter for Simplecov that emits a Vim script to mark up code files with coverage information.


Add to Gemfile:

gem 'simplecov'
gem 'simplecov-vim'


bundle install


gem install simplecov simplecov-vim

(If you already have simplecov installed, these commands have some redundancy


In .simplecov (or where ever you do this)

require 'simplecov-vim/formatter'
SimpleCov.start do
  formatter SimpleCov::Formatter::VimFormatter

Run your tests

rspec -rsimplecov spec

You'll find a shiny new file called coverage.vim in your project root.

Edit a file in your project with Vim. From Normal mode:

:so coverage.vim

And you should see nice marks in the left column for coverage. Green >> are covered lines, and red :( are uncovered.


The coverage.vim file is a self contained Vim script - feel free to examine it's contents. It'll be rewritten every time you run coverage, though, so editing is probably futile.

coverage.vim can be re-sourced safely between coverage runs - it'll clean up the old coverage signs before placing new ones.

coverage.vim adds two user commands: :Cov and :Uncov which can be used to toggle the state of coverage signs.

A slightly more advanced .simplecov configuration file that produces both simplecov.vim and SimpleCov's normal HTML output:

require 'simplecov-vim/formatter'

module SimpleCov::Formatter
  class MergedFormatter
    def initialize
      @formatters = [HTMLFormatter, VimFormatter].map{|frmt|}

    def format(result)
      @formatters.each{|frmt| frmt.format(result)}

SimpleCov.start 'rails' do
  formatter SimpleCov::Formatter::MergedFormatter
Something went wrong with that request. Please try again.