Gherkin Highlighting for VIM

Monday, June 21st, 2010

I really wanted some highlighting on my .feature files in vim, I’m no vim expert so I did a bit of googling and came up with the following:

  • Download cucumber.vim from http://github.com/tpope/vim-cucumber/blob/master/syntax/cucumber.vim
  • Save the file to ~/.vim/cucumber.vim (creating the directory if required)
  • vim ~/.vimrc and add the following lines

    au Bufread,BufNewFile *.feature set filetype=gherkin
    au! Syntax gherkin source ~/.vim/cucumber.vim
  • Make sure
    syntax on

    is also present

  • Open your feature file

If anyone knows a more vim way of doing this feel free to add a comment.

Tags: , , , , ,

7 Comments to Gherkin Highlighting for VIM

Mehul
July 1, 2010

That is a really neat feaature. Custom highlighting in VIM based on the file type. I didnt know you could do that.

I should look for some of these to make viewing XML files easier to read.

Richard Paul
July 3, 2010

Vim usually comes with XML syntax highlighting by default, you might need to turn syntax highlighting to auto to have it automatically picked up.

Petri
August 9, 2010

I can’t get this to work. I downloaded cucumber.vim, put it in /home/myacct/.vim/, added those lines in /home/myacct/.vimrc, but nothing happened.

Richard Paul
August 9, 2010

Hmmm, sorry Petri, all I can say is ‘it works on my machine’.

Brent J. Nordquist
June 12, 2011

Petri: Not sure if this will work better for you, but:

1. I downloaded the tpope cucumber.vim from the following URL, using curl or wget: https://raw.github.com/tpope/vim-cucumber/master/syntax/cucumber.vim

The http://github.com URL takes you to the vim-cucumber project page, whereas the https://raw.github.com URL is the link for the cucumber.vim file itself. Look inside your cucumber.vim after the download and make sure it looks like a vim file, and not like HTML.

2. I put the cucumber.vim file into ~/.vim/syntax not ~/.vim (and made the corresponding change to the path in .vimrc given above).

Jim Hopp
December 6, 2011

Instructions above didn’t work for me (MaxOSX 10.6.6, vim 7.2.108).

I was able to get it to work by doing this:
1. Move ~/.vim/cucumber.vim to ~/.vim/syntax/gherkin.vim
2. Remove the “au!” line in ~/.vimrc

Steve Love
December 20, 2011

It looks like the vimrc filetype and syntax commands listed here aren’t necessary. The cucumber.vim plugin on its own works perfectly.

Leave a comment