Reputation: 141200
I have the following commands in a README file:
./Setup ...
./Setup ...
./Setup ...
I want to run them by selecting the codes visually and then running them.
I run unsuccessfully
: '<,'> !
Current code after Luc's comments in his answer
My code in .vimrc which I have not managed to get to work:
vmap <silent> <leader>v y:exe '!'.join(split(@", "\n"),';')<cr>
I am trying to make make a keyboard combination for
v yy
How can you get the above command work, such that you can run file's commands directly in Vim?
Upvotes: 0
Views: 388
Reputation: 6469
This might be oversimplifying things, but why not just do:
:e README :%!bash
This filters the current file through bash, executing each line as a command. The current buffer is replaced by the output of running all of the commands in the file.
It might be helpful to do a :w RESULTS
to save it as another file first, so you don't accidentally overwrite the original:
:e README :w RESULTS :%!bash
You had said you wanted to do this with a visual selection, which would work just as well After you select what you want to execute, type :
. '<,'>
will automatically be prepended to the current command. '<
is the mark of the beginning of the current selection, whereas '>
is the mark at the end of the current selection. You can just run just those commands you have selected just like above:
:'<,'>!bash
This will replace just the selected commands with the output of executing those commands.
Upvotes: 1
Reputation: 32946
y
,and finally, you can execute:
:exe '!'.join(split(@", "\n"),';')
Upvotes: 5