Fast way to send current line to the shell in Vim
Say that the current line in Vim contains:
ls /home
(or whatever shell command). Thus, what is a fast way to send this line to the (bash) shell and read the results in Vim? And without using plug-ins.
vim shell
add a comment |
Say that the current line in Vim contains:
ls /home
(or whatever shell command). Thus, what is a fast way to send this line to the (bash) shell and read the results in Vim? And without using plug-ins.
vim shell
add a comment |
Say that the current line in Vim contains:
ls /home
(or whatever shell command). Thus, what is a fast way to send this line to the (bash) shell and read the results in Vim? And without using plug-ins.
vim shell
Say that the current line in Vim contains:
ls /home
(or whatever shell command). Thus, what is a fast way to send this line to the (bash) shell and read the results in Vim? And without using plug-ins.
vim shell
vim shell
asked Oct 12 '13 at 14:57
antonioantonio
3571930
3571930
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The easiest way is to put :!
at the front of the line (with I:!
), then yy
to yank the line into the unnamed register, and finally use @"
to call the unnamed ("
) register as a macro. To vim, this is exactly equivalent to typing
:!ls /home
in normal mode. If, like me, you have ;
and :
switched around in your .vimrc for normal mode, you'll have to insert a semicolon instead.
It's probably possible to alter the register in-place, rather than prepending to an actual line.
It's also possible to do it by y$
yanking to the end of the line (without the above editing), then typing
:!<c-r>"
...(<c-r>
meaning Ctrl+r) which will expand to
:!ls /home
(or whatever the command you yanked was). You need to use y$
rather than yy
because otherwise it will expand to
:ls /home^M
^M
there representing the newline; this is easy enough to delete with a single backspace, though.
This second method might be slightly faster, but anything that involves the Ctrl key seems faintly un-vim-like to me.
yy
plus:!c-r"Backspace
is 6 keystrokes, but probably the faster way. Btw what's the problem with^M
?
– antonio
Oct 12 '13 at 16:40
I'm not sure why exactly, but leaving it there prevents the command from working...
– evilsoup
Oct 12 '13 at 16:57
add a comment |
You can send the current line as a command by simply invoking:
:.!bash -e
The line in the opened buffered will be replaced by the output of that command.
If you'd rather preserve the original line, you can send the output to another buffer with:
:.w !bash -e
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f657947%2ffast-way-to-send-current-line-to-the-shell-in-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The easiest way is to put :!
at the front of the line (with I:!
), then yy
to yank the line into the unnamed register, and finally use @"
to call the unnamed ("
) register as a macro. To vim, this is exactly equivalent to typing
:!ls /home
in normal mode. If, like me, you have ;
and :
switched around in your .vimrc for normal mode, you'll have to insert a semicolon instead.
It's probably possible to alter the register in-place, rather than prepending to an actual line.
It's also possible to do it by y$
yanking to the end of the line (without the above editing), then typing
:!<c-r>"
...(<c-r>
meaning Ctrl+r) which will expand to
:!ls /home
(or whatever the command you yanked was). You need to use y$
rather than yy
because otherwise it will expand to
:ls /home^M
^M
there representing the newline; this is easy enough to delete with a single backspace, though.
This second method might be slightly faster, but anything that involves the Ctrl key seems faintly un-vim-like to me.
yy
plus:!c-r"Backspace
is 6 keystrokes, but probably the faster way. Btw what's the problem with^M
?
– antonio
Oct 12 '13 at 16:40
I'm not sure why exactly, but leaving it there prevents the command from working...
– evilsoup
Oct 12 '13 at 16:57
add a comment |
The easiest way is to put :!
at the front of the line (with I:!
), then yy
to yank the line into the unnamed register, and finally use @"
to call the unnamed ("
) register as a macro. To vim, this is exactly equivalent to typing
:!ls /home
in normal mode. If, like me, you have ;
and :
switched around in your .vimrc for normal mode, you'll have to insert a semicolon instead.
It's probably possible to alter the register in-place, rather than prepending to an actual line.
It's also possible to do it by y$
yanking to the end of the line (without the above editing), then typing
:!<c-r>"
...(<c-r>
meaning Ctrl+r) which will expand to
:!ls /home
(or whatever the command you yanked was). You need to use y$
rather than yy
because otherwise it will expand to
:ls /home^M
^M
there representing the newline; this is easy enough to delete with a single backspace, though.
This second method might be slightly faster, but anything that involves the Ctrl key seems faintly un-vim-like to me.
yy
plus:!c-r"Backspace
is 6 keystrokes, but probably the faster way. Btw what's the problem with^M
?
– antonio
Oct 12 '13 at 16:40
I'm not sure why exactly, but leaving it there prevents the command from working...
– evilsoup
Oct 12 '13 at 16:57
add a comment |
The easiest way is to put :!
at the front of the line (with I:!
), then yy
to yank the line into the unnamed register, and finally use @"
to call the unnamed ("
) register as a macro. To vim, this is exactly equivalent to typing
:!ls /home
in normal mode. If, like me, you have ;
and :
switched around in your .vimrc for normal mode, you'll have to insert a semicolon instead.
It's probably possible to alter the register in-place, rather than prepending to an actual line.
It's also possible to do it by y$
yanking to the end of the line (without the above editing), then typing
:!<c-r>"
...(<c-r>
meaning Ctrl+r) which will expand to
:!ls /home
(or whatever the command you yanked was). You need to use y$
rather than yy
because otherwise it will expand to
:ls /home^M
^M
there representing the newline; this is easy enough to delete with a single backspace, though.
This second method might be slightly faster, but anything that involves the Ctrl key seems faintly un-vim-like to me.
The easiest way is to put :!
at the front of the line (with I:!
), then yy
to yank the line into the unnamed register, and finally use @"
to call the unnamed ("
) register as a macro. To vim, this is exactly equivalent to typing
:!ls /home
in normal mode. If, like me, you have ;
and :
switched around in your .vimrc for normal mode, you'll have to insert a semicolon instead.
It's probably possible to alter the register in-place, rather than prepending to an actual line.
It's also possible to do it by y$
yanking to the end of the line (without the above editing), then typing
:!<c-r>"
...(<c-r>
meaning Ctrl+r) which will expand to
:!ls /home
(or whatever the command you yanked was). You need to use y$
rather than yy
because otherwise it will expand to
:ls /home^M
^M
there representing the newline; this is easy enough to delete with a single backspace, though.
This second method might be slightly faster, but anything that involves the Ctrl key seems faintly un-vim-like to me.
edited Oct 12 '13 at 16:10
answered Oct 12 '13 at 15:49
evilsoupevilsoup
8,87714465
8,87714465
yy
plus:!c-r"Backspace
is 6 keystrokes, but probably the faster way. Btw what's the problem with^M
?
– antonio
Oct 12 '13 at 16:40
I'm not sure why exactly, but leaving it there prevents the command from working...
– evilsoup
Oct 12 '13 at 16:57
add a comment |
yy
plus:!c-r"Backspace
is 6 keystrokes, but probably the faster way. Btw what's the problem with^M
?
– antonio
Oct 12 '13 at 16:40
I'm not sure why exactly, but leaving it there prevents the command from working...
– evilsoup
Oct 12 '13 at 16:57
yy
plus :!c-r"Backspace
is 6 keystrokes, but probably the faster way. Btw what's the problem with ^M
?– antonio
Oct 12 '13 at 16:40
yy
plus :!c-r"Backspace
is 6 keystrokes, but probably the faster way. Btw what's the problem with ^M
?– antonio
Oct 12 '13 at 16:40
I'm not sure why exactly, but leaving it there prevents the command from working...
– evilsoup
Oct 12 '13 at 16:57
I'm not sure why exactly, but leaving it there prevents the command from working...
– evilsoup
Oct 12 '13 at 16:57
add a comment |
You can send the current line as a command by simply invoking:
:.!bash -e
The line in the opened buffered will be replaced by the output of that command.
If you'd rather preserve the original line, you can send the output to another buffer with:
:.w !bash -e
add a comment |
You can send the current line as a command by simply invoking:
:.!bash -e
The line in the opened buffered will be replaced by the output of that command.
If you'd rather preserve the original line, you can send the output to another buffer with:
:.w !bash -e
add a comment |
You can send the current line as a command by simply invoking:
:.!bash -e
The line in the opened buffered will be replaced by the output of that command.
If you'd rather preserve the original line, you can send the output to another buffer with:
:.w !bash -e
You can send the current line as a command by simply invoking:
:.!bash -e
The line in the opened buffered will be replaced by the output of that command.
If you'd rather preserve the original line, you can send the output to another buffer with:
:.w !bash -e
answered Jan 26 at 17:30
shimeshime
1064
1064
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f657947%2ffast-way-to-send-current-line-to-the-shell-in-vim%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