Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
10 years, 9 months ago
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")
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?
Aug 25, 2012 at 5:59
3,981 10 10 gold badges 50 50 silver badges 78 78 bronze badges
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.
Aug 25, 2012 at 6:16
35.5k 17 17 gold badges 79 79 silver badges 82 82 bronze badges
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
Sep 5, 2012 at 8:24
Steve Kroon Steve Kroon
1,014 2 2 gold badges 10 10 silver badges 26 26 bronze badges
Here is alternative way of pasting output from external command before the cursor:
:exe 'norm i' . system("ls -l")
or use expression register (
P. Or shorter way by:
Oct 17, 2015 at 23:49
9,846 2 2 gold badges 76 76 silver badges 90 90 bronze badges
In addition to
p, we can also employ vim's functions
put like so:
f was chosen in this example simply for mnemonic representation for the word "files". There's nothing particularly special about it and you're free to choose your own register.
Dec 27, 2019 at 8:19
Sergiy Kolodyazhnyy Sergiy Kolodyazhnyy
102k 19 19 gold badges 271 271 silver badges 483 483 bronze badges
:r command takes a line range into which the results will be read. In vim command lines, "
." in a range means "the current line." So
:r ... is equivalent to
:.r ..., and means "put what I'm reading after the current line.
You're free to specify the range to write to using an expression based on
.. Specifically, the thing you're asking for should be easily done with:
:.-1r !ls somefilename
Dec 2, 2021 at 20:03
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only