When we execute any system command and get the output, it prints in next line. But I want it in current line, next to the cursor or in place of cursor (not at the start of the current line)


:r! ls

Prints the list of files in the current folder.

But this prints the output in next line. Is there any way to print the output in the current line, next to the cursor?

Some example situations:

  • listing of files inside quotes
  • executing a perl/external program and getting its output pasted here.

In normal mode press double !, then enter the command, or just type the following:


One can execute any external command in command line using the system function:

:let @a = system("ls -ltr")

And when you want to paste, press Ctrl+R and immediately a to paste the content next to cursor.

@a is the register name. You can use whatever register you want.

  • 1
    This is useful. But, I had to learn more tricks to get this done. I first tried executing the command needed to get the resultant text using :!. Then, had to enter into command-editing mode using Ctrl-F. Edit the command to create register @a as mentioned in this answer. And hit Enter key <CR> to get it executed. More on how to do get into command-editing mode at : stackoverflow.com/a/2078230/4106458 – Sarfraaz Ahmed Mar 18 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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