How do I redirect command output to vim in bash?
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?
bash vim vi
add a comment |
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?
bash vim vi
add a comment |
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?
bash vim vi
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?
bash vim vi
bash vim vi
edited Aug 26 '15 at 1:00
muru
1
1
asked Aug 13 '14 at 16:13
faizalfaizal
1,13261826
1,13261826
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
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 -
2
<(ls -la)
is actually process substitution rather than command substitution.
– Eliah Kagan
Sep 2 '14 at 1:32
1
I really like vim's option, it allows me to search, find and save the output easily from data dumps.
– Josue Alexander Ibarra
May 11 '16 at 21:36
add a comment |
You're really close on your own. You were just missing one character.
ls -la | vim -
7
Well technically it's two characters. ;)
– Cory Klein
Oct 24 '17 at 22:14
add a comment |
Here's another approach, hopefully to teach someone something new.
If you know that the command :r !ls -la
works inside vim, you can do the following to open vim and make it run the command as soon as it opens, straight from bash:
vim -c ':r! ls -la'
This is the equivalent of opening vim
then executing the command :r! ls -la
. This should work with any vim
command, where the command comes after the -c
option.
add a comment |
You can tell vim to open stdin:
ls -la | vim -
add a comment |
If your goal is simply to get the output into a text file then you don't need to invoke vim. Bash can do it alone with
ls -la > outputfile.txt
add a comment |
setlocal buftype=nofile
This is a good option if you are going to create an alias to replace less
:
seq 100 | vim +':setlocal buftype=nofile' -
Now you don't need to type the ! to quit.
Another option is:
seq 100 | vim +'nnoremap q :quit!' -
so you can exit with just q<enter>
.
Good idea. Definitely shorter than typing this long ! :)
– kode
Jun 21 '17 at 15:04
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f510890%2fhow-do-i-redirect-command-output-to-vim-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 -
2
<(ls -la)
is actually process substitution rather than command substitution.
– Eliah Kagan
Sep 2 '14 at 1:32
1
I really like vim's option, it allows me to search, find and save the output easily from data dumps.
– Josue Alexander Ibarra
May 11 '16 at 21:36
add a comment |
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 -
2
<(ls -la)
is actually process substitution rather than command substitution.
– Eliah Kagan
Sep 2 '14 at 1:32
1
I really like vim's option, it allows me to search, find and save the output easily from data dumps.
– Josue Alexander Ibarra
May 11 '16 at 21:36
add a comment |
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 -
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 -
edited Aug 26 '15 at 0:58
muru
1
1
answered Aug 13 '14 at 16:58
chaoschaos
19.7k85968
19.7k85968
2
<(ls -la)
is actually process substitution rather than command substitution.
– Eliah Kagan
Sep 2 '14 at 1:32
1
I really like vim's option, it allows me to search, find and save the output easily from data dumps.
– Josue Alexander Ibarra
May 11 '16 at 21:36
add a comment |
2
<(ls -la)
is actually process substitution rather than command substitution.
– Eliah Kagan
Sep 2 '14 at 1:32
1
I really like vim's option, it allows me to search, find and save the output easily from data dumps.
– Josue Alexander Ibarra
May 11 '16 at 21:36
2
2
<(ls -la)
is actually process substitution rather than command substitution.– Eliah Kagan
Sep 2 '14 at 1:32
<(ls -la)
is actually process substitution rather than command substitution.– Eliah Kagan
Sep 2 '14 at 1:32
1
1
I really like vim's option, it allows me to search, find and save the output easily from data dumps.
– Josue Alexander Ibarra
May 11 '16 at 21:36
I really like vim's option, it allows me to search, find and save the output easily from data dumps.
– Josue Alexander Ibarra
May 11 '16 at 21:36
add a comment |
You're really close on your own. You were just missing one character.
ls -la | vim -
7
Well technically it's two characters. ;)
– Cory Klein
Oct 24 '17 at 22:14
add a comment |
You're really close on your own. You were just missing one character.
ls -la | vim -
7
Well technically it's two characters. ;)
– Cory Klein
Oct 24 '17 at 22:14
add a comment |
You're really close on your own. You were just missing one character.
ls -la | vim -
You're really close on your own. You were just missing one character.
ls -la | vim -
answered Aug 13 '14 at 16:18
Cris HoldorphCris Holdorph
524148
524148
7
Well technically it's two characters. ;)
– Cory Klein
Oct 24 '17 at 22:14
add a comment |
7
Well technically it's two characters. ;)
– Cory Klein
Oct 24 '17 at 22:14
7
7
Well technically it's two characters. ;)
– Cory Klein
Oct 24 '17 at 22:14
Well technically it's two characters. ;)
– Cory Klein
Oct 24 '17 at 22:14
add a comment |
Here's another approach, hopefully to teach someone something new.
If you know that the command :r !ls -la
works inside vim, you can do the following to open vim and make it run the command as soon as it opens, straight from bash:
vim -c ':r! ls -la'
This is the equivalent of opening vim
then executing the command :r! ls -la
. This should work with any vim
command, where the command comes after the -c
option.
add a comment |
Here's another approach, hopefully to teach someone something new.
If you know that the command :r !ls -la
works inside vim, you can do the following to open vim and make it run the command as soon as it opens, straight from bash:
vim -c ':r! ls -la'
This is the equivalent of opening vim
then executing the command :r! ls -la
. This should work with any vim
command, where the command comes after the -c
option.
add a comment |
Here's another approach, hopefully to teach someone something new.
If you know that the command :r !ls -la
works inside vim, you can do the following to open vim and make it run the command as soon as it opens, straight from bash:
vim -c ':r! ls -la'
This is the equivalent of opening vim
then executing the command :r! ls -la
. This should work with any vim
command, where the command comes after the -c
option.
Here's another approach, hopefully to teach someone something new.
If you know that the command :r !ls -la
works inside vim, you can do the following to open vim and make it run the command as soon as it opens, straight from bash:
vim -c ':r! ls -la'
This is the equivalent of opening vim
then executing the command :r! ls -la
. This should work with any vim
command, where the command comes after the -c
option.
answered Aug 13 '14 at 17:11
Alaa AliAlaa Ali
22.5k96994
22.5k96994
add a comment |
add a comment |
You can tell vim to open stdin:
ls -la | vim -
add a comment |
You can tell vim to open stdin:
ls -la | vim -
add a comment |
You can tell vim to open stdin:
ls -la | vim -
You can tell vim to open stdin:
ls -la | vim -
answered Aug 13 '14 at 16:20
iffyiffy
9521712
9521712
add a comment |
add a comment |
If your goal is simply to get the output into a text file then you don't need to invoke vim. Bash can do it alone with
ls -la > outputfile.txt
add a comment |
If your goal is simply to get the output into a text file then you don't need to invoke vim. Bash can do it alone with
ls -la > outputfile.txt
add a comment |
If your goal is simply to get the output into a text file then you don't need to invoke vim. Bash can do it alone with
ls -la > outputfile.txt
If your goal is simply to get the output into a text file then you don't need to invoke vim. Bash can do it alone with
ls -la > outputfile.txt
answered Mar 24 '17 at 15:44
Jake StewartJake Stewart
111
111
add a comment |
add a comment |
setlocal buftype=nofile
This is a good option if you are going to create an alias to replace less
:
seq 100 | vim +':setlocal buftype=nofile' -
Now you don't need to type the ! to quit.
Another option is:
seq 100 | vim +'nnoremap q :quit!' -
so you can exit with just q<enter>
.
Good idea. Definitely shorter than typing this long ! :)
– kode
Jun 21 '17 at 15:04
add a comment |
setlocal buftype=nofile
This is a good option if you are going to create an alias to replace less
:
seq 100 | vim +':setlocal buftype=nofile' -
Now you don't need to type the ! to quit.
Another option is:
seq 100 | vim +'nnoremap q :quit!' -
so you can exit with just q<enter>
.
Good idea. Definitely shorter than typing this long ! :)
– kode
Jun 21 '17 at 15:04
add a comment |
setlocal buftype=nofile
This is a good option if you are going to create an alias to replace less
:
seq 100 | vim +':setlocal buftype=nofile' -
Now you don't need to type the ! to quit.
Another option is:
seq 100 | vim +'nnoremap q :quit!' -
so you can exit with just q<enter>
.
setlocal buftype=nofile
This is a good option if you are going to create an alias to replace less
:
seq 100 | vim +':setlocal buftype=nofile' -
Now you don't need to type the ! to quit.
Another option is:
seq 100 | vim +'nnoremap q :quit!' -
so you can exit with just q<enter>
.
edited Jan 30 at 12:25
answered Jan 29 '17 at 14:43
Ciro Santilli 新疆改造中心 六四事件 法轮功Ciro Santilli 新疆改造中心 六四事件 法轮功
10.2k44751
10.2k44751
Good idea. Definitely shorter than typing this long ! :)
– kode
Jun 21 '17 at 15:04
add a comment |
Good idea. Definitely shorter than typing this long ! :)
– kode
Jun 21 '17 at 15:04
Good idea. Definitely shorter than typing this long ! :)
– kode
Jun 21 '17 at 15:04
Good idea. Definitely shorter than typing this long ! :)
– kode
Jun 21 '17 at 15:04
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f510890%2fhow-do-i-redirect-command-output-to-vim-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown