Skip to content

Instantly share code, notes, and snippets.

@leviable
Last active January 13, 2021 12:59
Show Gist options
  • Save leviable/5d2c415e1964710f9ad4780172700538 to your computer and use it in GitHub Desktop.
Save leviable/5d2c415e1964710f9ad4780172700538 to your computer and use it in GitHub Desktop.
VIM + Tabularize recipe to align Cucumber Feature Files on the space after the Step keyword

Map commands in .vimrc to align Cucumber complient Feature File steps on the space after the keywords:

" Use Tabularize to set shortcute `,as` to align on feature file step keywords
let mapleader=','
nmap <Leader>as :Tab /^\W*[Given\|When\|Then\|And][a-zA-Z]*\zs\W/r0c0l0<CR>
vmap <Leader>as :Tab /^\W*[Given\|When\|Then\|And][a-zA-Z]*\zs\W/r0c0l0<CR>

So this:

Feature: VIM Tabularize Align Example

Scenario Outline: Tabularize can align steps
    Given I have a foo
    When I do bar
    And bar responds
    Then the bar response has <resp-obj>
    And the bar response is successful

    Examples: Bar Responses
    | resp-obj |
    | baz      |
    | egg.     |
    | spam.    |

Becomes this:

Feature: VIM Tabularize Align Example

Scenario Outline: Tabularize can align steps
    Given I have a foo
     When I do bar
      And bar responds
     Then the bar response has <resp-obj>
      And the bar response is successful

    Examples: Bar Responses
    | resp-obj |
    | baz      |
    | egg.     |
    | spam.    |
@leviable
Copy link
Author

My regex-fu is weak, so this can almost certainly be optimized and improved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment