Pass filename and current line to shell script

shellvim

I would like to pass the file name and the current line number where my cursor is at, separated by colon, to an external shell script. For example, if am editing the file "foo.c" and I am currently on line 77, I'd like to call my script from vim with the argument "foo.c:77".

Best Answer

An alternative to Karalos's answer:

:call system('echo ' . expand('%') . ':' . line('.'))

Of course, you replace "echo" with the name of your shell script.

The advantage of system() is that it returns the output of the command run, so you can capture it for further use in a Vim script if you need to.

You may need to look at the modifiers in :help expand() if you need to qualify/modify the filename in any way.

Related Question