Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

In vim, when I use

:r !ls somefilename

it inserts output of that command on a new line below the current line.

If I do

let @a = system("ls")

and later


it still inserts the output on a new line below the current line.

Is there a way to make vim insert output at the current location?

share|improve this question
up vote 7 down vote accepted

You can paste the contents of the clipboard buffer between characters with Ctrl-R * in insert mode (and a similar approach for other buffers). So if you can get the system command into a buffer, you should be set. (Source: ).

:let @a=system("ls -l") will put the output of ls -l into register a. You can then paste it (in insert mode) with ^R-a.

share|improve this answer
:r !command 

will read the output from the command and insert it into the line under the current line. This is how vi is programmed you cannot change the behavior.

But say if you are in line number 3. If you try :r !date. It will insert the date value into line number 4.

If you want the date value to be appeared on line number 3, then you try :2r !date will insert the date value in line number 3.

share|improve this answer
That inserts on a different line, but still on a line of its own. I want to insert it at the current location! – deshmukh Aug 25 '12 at 6:48

Here is alternative way of pasting output from external command before the cursor:

:exe 'norm i' . system("ls -l")

or use expression register (:help @=):

"=system('ls -la')

then press P.

share|improve this answer

Your Answer


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.