Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
199
rated 0 times [  199] [ 0]  / answers: 1 / hits: 75605  / 3 Years ago, mon, october 18, 2021, 2:44:02

I am trying to redirect the output of a bash command into a new file.



If I try the pipe as below :



ls -la | vim


Bash shows me the errors :



Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.


I know that I can open Vim and then use :



:r !ls -la


But is there a way to do this in bash itself, so that Vim is opened and the output is pasted there automatically?


More From » bash

 Answers
5

You can use process substitution (this also works with applications that can't read from STDIN):



vim <(ls -la)


Or use vim's function to read from STDIN:



ls -la | vim -

[#23658] Monday, October 18, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
enefiama

Total Points: 43
Total Questions: 125
Total Answers: 102

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;