4

I know how to run shell commands within vim using :!r and :!, but is there a way I can do that from outside, i.e. from bash?

Something along the lines of vim 'ls -al'. The output of ls should be in vim and editable.

migrated from stackoverflow.com Jan 16 '13 at 1:31

This question came from our site for professional and enthusiast programmers.

15

You can read stdin

$ ls -al | vim -
6

Execute the command the same way you would any command from the command line.

$ vim '+r !ls -al'
2

You can use bash process substitution like this:

vim <(ls -al)

See "Process Substitution" subsection of the bash manual:

man -P 'less +/Process\ Substitution' bash

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.