How to execute a shell-command in Vim, and have the result printed below?
5,135
Solution 1
As Clausi pointed out, yyp!!sh
yanks (copies) the current line to the register, pastes that line below the original one, and replaces the bottom one with the output of the command.
To save keystrokes you can map this action by adding the next line in the ~/.vimrc
file:
map <F5> yyp!!sh<CR><Esc>
This way everytime F5 is pressed in command mode, the line will be executed and the result will be shown below the line.
Solution 2
What about copying/pasting the line before executing (something like yyp!!sh
)?
Related videos on Youtube
Author by
zarsiwala
Updated on September 17, 2022Comments
-
zarsiwala over 1 year
I'd like to edit shell commands from vim, and execute them from vim. Currently I use
!!sh
(pipes current line to command sh), but this removes the line itself.Is it possible to execute the command in a shell, and paste the result below that line?