Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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".

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
Also: consider using shellescape() to protect any special characters. – Chris Johnsen Aug 29 '12 at 3:07

Although quite cumbersome, you could try the following

:!echo %:<Ctrl+R>=line(".")<CR><CR>

or you could use an intermediate variable

:let l=line(".")

and call

:!echo %:<Ctrl+R>=l<CR><CR>
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .