Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.