5

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?

Rad'Val
  • 223
  • There's no such thing as a “shell scrollback buffer”, that's a feature of the terminal. Are you running your shell inside screen or not? If not, in what terminal emulator? What do you mean by “screen just lets me use a old simple vi” — I don't see what screen has to do with what software you can use? – Gilles 'SO- stop being evil' Nov 03 '17 at 21:24
  • @Gilles You're right of course, I modified the title. I've always been confused about where's what implemented in the relation between terminal and shell. I run iTerm. I'm ready to use screen as well. Is not 'vi' per see I think, but if you use screen an Ctrl-A + [ you can copy from the scrollback, however, you're in a vi-like editor, without the power of vim + plugins. – Rad'Val Nov 03 '17 at 21:35
  • Oh, I see. When you use Ctrl-A [, you're still in Screen, this has nothing to do with Vi except that a couple of key bindings are inspired from vi. – Gilles 'SO- stop being evil' Nov 03 '17 at 21:41

2 Answers2

6

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.)

0

If you don't mind running the command again, you can always do

<command> | vim -

If you also care about stderr:

<command> 2>&1 | vim -

Specially useful if you want to search for a pattern and open vim in that location:

grep -iIrHn <pattern> | vim -

then place the cursor at the line line of the pattern and press gF

Hobber
  • 378
  • 1
  • 11