Gherkin Highlighting for VIM
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.
7 Comments to Gherkin Highlighting for VIM
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.
Vim usually comes with XML syntax highlighting by default, you might need to turn syntax highlighting to auto to have it automatically picked up.
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.
Hmmm, sorry Petri, all I can say is ‘it works on my machine’.
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).
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
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
Subscribe
Recent Posts
Tags
- "Sorry, no matches found for “tdd” near Auckland, New Zealand" http://t.co/Ahc736MX #auckland #whowantstostartonewithme 2 weeks ago
- Great series on the SOLID design principles for JavaScript http://t.co/ELoPuOH2 2 weeks ago
- Auckland devs, what meetups should I be attending? #java #groovy #ruby #javascript #bdd #tdd 2 weeks ago
- More updates...

July 1, 2010