Skip to content
Mathias Lafeldt edited this page Nov 27, 2014 · 3 revisions

As a matter of fact, I primarily wrote chef-runner for use with Vim. Instead of jumping back and forth between editing a Chef recipe and running vagrant provision, I wanted to be able to change some code and get immediate feedback without having to leave the editor. This is where chef-runner's ability to run a single recipe file -- the file currently open in Vim -- comes in handy.

There's no Vim plugin (yet). For now, you can just stick this one-liner in your .vimrc:

nnoremap <leader>r :w\|!chef-runner %<cr>

With this key mapping in place, make sure that the target machine is up and open a recipe in Vim:

$ vim recipes/default.rb

Now whenever you type <leader>r (your leader key then r), chef-runner will run the current recipe on the target machine, giving you fast feedback on local code changes. (As a bonus, the mapping will also save the file for you.)

Of course, you can also change the key mapping to include whatever chef-runner options you need. For example, I like using a Chef output format that is less verbose:

nnoremap <leader>r :w\|!chef-runner -F min -l warn %<cr>

Last but not least, you can always reprogram the Vim key mapping at runtime if you need to pass project-specific options like host or machine name:

:nnoremap <leader>r :w\|!chef-runner -F min -l warn -H example.local %<cr>
You can’t perform that action at this time.