1

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)
12
  • What do you mean exactly by "It crashed my instance"? Because I just tried to execute a loop echoing 200 lines with :'<,'>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 with j and k and go back to the buffer with q.
    – statox
    Sep 22, 2015 at 0:31
  • I cant remember the shell command I ran but it vim showed a bunch of errors then locked up vim. after that I also read that the | character has a different meaning on vims command prompt, so after that I didnt risk trying piping into less. will give it another go though Sep 22, 2015 at 0:43
  • Indeed in vim command line | 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 :-)
    – statox
    Sep 22, 2015 at 1:12
  • @statox thanks, I tried piping into less again, and it worked once. However I just tried executing a long list of echo statements - I thought executing interactive commands like read would cause problems so I avoided that. Im getting E388: Couldn't find definition. again vim unresponsive - so Ive had to kill the shell process Sep 22, 2015 at 3:15
  • E388 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)?
    – statox
    Sep 22, 2015 at 3:23

1 Answer 1

2

Clam is very useful for that kind of scenario:

  1. select a bunch of lines,
  2. do :'<,'>Clam bash
  3. get the result in a vertical Vim window,
  4. go back to your script, edit it, run it again in the same vertical window.
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.