When Im writing shell scripts I often want to run/check a block of code, by
- V highlight block
- then
:'<,'>w !bash
vim will then execute highlighted block and display output at the bottom of vim's display - displacing the current buffer with the shell output.
The problem is sometimes the output goes beyond the top of the screen and when in that state, no key commands to navigate the text seem available - i.e. any key just returns back to the buffer.
Ive tried piping into less, e.g. :'<,'>w !bash | less
, this actually crashed my vim instance!
How can I display the output in a useful way, e.g.
- move around the existing output, kind of like less (ideal)
- sending large output to a new buffer (good)
- sending output into a new file (ok, if no better options)
:'<,'>w !bash | less
and it seems to work perfectly on a terminal vim 7.4 on Debian. I can move up and down the lines withj
andk
and go back to the buffer withq
.|
can be used to separate commands, so you can give multiple commands in one. But as you use!
you're calling external shell command so in your example it works as a classical shell pipe. Give us an update and more details when you'll have reproduced you the crashing with the pipe :-)read
would cause problems so I avoided that. Im gettingE388: Couldn't find definition
. again vim unresponsive - so Ive had to kill the shell processE388
indicates that the definition of a function or of a variable can't be found (:h E388
) so are you sure your script is working? Did you tried to execute it directly from your shell (not in vim)?