NashPL
NashPL

Reputation: 481

Vim Commands and mapping

Hi I am trying to make a VIM mapping to run a script when I press F2. I am struggle to get a full path for the file that is being edited with vim into the command function.

nnoremap <F2> :! php /home/kbuczynski/diff_re.php fix <full file path here> flagArg

Any idea ?

Upvotes: 3

Views: 80

Answers (2)

Luc Hermitte
Luc Hermitte

Reputation: 32936

You don't need :execute and expand() if you have no other variable to inject. You should be able to use %:p directly.

nnoremap <F2> :!php /home/kbuczynski/diff_re.php fix %:p flagArg<cr>

If you need to read flagArg somewhere else, well, then you'll need :execute.

Upvotes: 3

Jonathan.Brink
Jonathan.Brink

Reputation: 25383

You can get the full path to the current buffer with:

expand('%:p')

Your mapping could look something like this (you will also need to use the execute function):

function! CallPHP()
    execute '!php /home/kbuczynski/diff_re.php fix '.expand('%:p').' flagArg'
endfunction
nnoremap <F2> :call CallPHP()<CR>

Here is some good documentation on dealing with file paths.

Upvotes: 5

Related Questions