Way to open screen’s terminal scrollback buffer in vim

gnu-screenvim

I'm looking for a way to drop the mouse, forever and always. I got to a very comfortable point, where I don't use it for regular text editing, however, something's bothering me.
When I work with the shell and I want to copy some prev output, I need to highlight + copy using the mouse. That sucks. I know about screen and 'Ctrl-A [', is cool, but I want to browse the scrollback in Vim, not in Screen's built-in interface.

Is there a way for me to open the current shell output buffer into Vim and copy from it?

Best Answer

From within a Screen window, run

screen -X hardcopy -h s
vim s
rm s

hardcopy -h dumps the scrollback into a temporary file which you can then open in Vim if you like. If you script this you should use a proper temporary file name:

#!/bin/sh
scrollback_file=$(mktemp)
screen -X hardcopy -h "$scrollback_file"
vim -c 'call delete(@%)' "$scrollback_file"

(Or you could just run your shell in Emacs or in Neovim.)

Related Question