I often create a temporary mapping to do something on a particular file.
Typical example is this:
:map <leader>f :w<cr>:! bundle exec cucumber features/account/sign_in.feature:41<cr>
I want the file features/account/sign_in.feature to be autocompleted from the current directory.
This should simply save the current file and shell out on <leader>f to run the command.
It allows me to easily work on a piece of code not thinking about jumping to a particular file and run it.
The problem is that creating such a binding is cumbersome and error prone.
VIM doesn’t allow completing the file name when mapping. Also using % is totally different ( I want to map to a file statically).
What is a better way of doing it?
Thanks.
Allthough I think your question should be made a lot clearer, here are some hints:
Will correctly save and insert current filename/line number in the command
Also, you will want to know about the
autowriteoption:Lastly, I usually employ
makeprgfor this kind of purpose:This has the added benefit of working with quickfix commands (
:copen,:colder,:cnewer) and (given a correctmakef) also jumping to error lines