Vim: Cucumber indentation for "And" lines
In Cucumber's Gherkin language, it's allowed to indent And lines, like so:
Scenario:
Given there is a user named Chris
And I am logged in as Chris
When I go to the home page
Then I should see "hi Chris"
And I should not see "log in"
I like this indentation style much better than the equally-indented style, but with Tim's Cucumber scripts for Vim, I have to manually 开发者_开发技巧indent the And lines and manually dedent the following lines, and sometimes Vim will automatically indent lines and it ends up all wrong.
What's the best way to work with indented And lines in Vim? Or is it easiest to just give up on it?
I think you could customize indent/cucumber.vim
(online here) to increase the indent on lines starting with ^\s*And
.
Here's a diff for indent/cucumber.vim
based on Andy's answer:
--- .vim/indent/cucumber.vim.bak 2011-03-24 18:44:27.000000000 +0100
+++ .vim/indent/cucumber.vim 2011-03-24 19:09:41.000000000 +0100
@@ -47,6 +47,10 @@
return indent(prevnonblank(v:lnum-1)) + &sw
elseif cline =~# '^\s*[^|# \t]' && line =~# '^\s*|'
return indent(prevnonblank(v:lnum-1)) - &sw
+ elseif cline =~# '^\s*\%(And\|But\)' && line !~# '^\s*\%(And\|But\)'
+ return indent(prevnonblank(v:lnum-1)) + &sw
+ elseif cline !~# '^\s*\%(And\|But\)' && line =~# '^\s*\%(And\|But\)'
+ return indent(prevnonblank(v:lnum-1)) - &sw
elseif cline =~# '^\s*$' && line =~# '^\s*|'
let in = indent(prevnonblank(v:lnum-1))
return in == indent(v:lnum) ? in : in - &sw
精彩评论