Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing line number from vim to external command

Tags:

vim

I am using VIM and I would like to pass the current line number to an external program.

something like this: map <F3> :!mycmd <linenumber><CR>

I tried to substitute <linenumber> for line('.'), line("."), . and others, but nothing seems to work. Thanks.

like image 941
yoki Avatar asked Sep 15 '25 03:09

yoki


1 Answers

You must use :execute to use a variable or expression in your mapping:

nnoremap <F3> :execute ":!echo " . line('.')<CR>
like image 196
romainl Avatar answered Sep 16 '25 23:09

romainl