1. Is there a way I can directly import/insert the output of any linux command into vim editor? For example: pwd in currently open vim buffer.


  1. From terminal how can I directly open command output for manipulation? For example: opening lshw output in vim and filter unwanted info and quick save file.

2 Answers 2


Import shell output

Launch vi or vim and try:


The output will be pasted in the current buffer

Checkout the possible options:

:help !!

Pipe stdout to vim


pwd | vi -
  • 2
    !!pwd in vim execution mode doesnt seems to work for me. However, as @statox suggested :read !pwd works perfectly. And thankyou for pipe stdout to vim - exactly what I needed :D Apr 27, 2018 at 14:52
  • 3
    @AviMehenwal to clarify this answer: !! should be use in normal mode (not in command line mode). This will open the command line with :.! and you can then type your command to get :.!pwd which means insert the result of the external command !pwd at the current line . you can also use :$!pwd to put the result on the last line, :1!ls -l to put the result on the first line or use whatever line number you want.
    – statox
    Apr 27, 2018 at 15:02
  • Amazing ... hacky way to get things done :) Thanks for explanation and it works like you suggested. Apr 27, 2018 at 16:33
  • 3
    @statox :.!pwd does not mean "insert the result of the external command at the current line". It means "write the current line as the input to the external command and replace this line with the output". The current line is being filtered through the external command. To simply insert the output of a command after a certain line, the desired address should be used as the range for :[range]read !cmd.
    – jamessan
    Apr 29, 2018 at 19:31
  • pwd | vim - worked great
    – stevec
    Jun 4, 2023 at 0:42

You could use :read (see :h :read):

:[range]r[ead] [++opt] !{cmd}
          Execute {cmd} and insert its standard output below
          the cursor or the specified line.  A temporary file is

For example: :read ! pwd will put the current working directory at the cursor position.

Note that you can pipe your command to grep to filter what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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