Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim Commands and mapping

Tags:

vim

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 ?

like image 248
NashPL Avatar asked Feb 13 '26 22:02

NashPL


1 Answers

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.

like image 128
Jonathan.Brink Avatar answered Feb 15 '26 16:02

Jonathan.Brink



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!