How can I navigate terminal output like a text file with Vim keybinding?
I use Neovim which has a really cool feature where if I type :terminal
it loads a terminal emulator inside Neovim. The interesting thing about this terminal emulator is that at any time I can type CTRL-\ CTRL-N and navigate the output like I would any text file. This allows me to scroll up to some part of the output and copy the text to my clipboard.
I would love this ability in a regular terminal. Is there any way for me to do this? I use Zsh now but as much as I have looked I can’t find a way to get the benefits of navigating a terminal output like I would inside Neovim. Preferably I would like to be able to navigate with Vim commands.
Solution 1:
I'll second the comment mentioning tmux
. Like it's older cousin screen
, this is a terminal multiplexer. That mean that you can have multiple shells inside a single physical terminal (emulator). Like Vim, tmux supports split windows, multiple tab pages, and a special copy mode, in which you can scroll back and capture text. You enter this mode via <C-B>[
; Ctrl-B is the default prefix key that all tmux commands start with. (All of this is configurable, similar to Vim.)
As a Vim user, you probably prefer vi-style key bindings. Put this into your ~/.tmux.conf
:
# Use Vim key bindings.
setw -g mode-keys vi
set -g status-keys vi
As for yanking to clipboard, you'll find configuration snippets that do that on the Internet. Or use the tmux-yank plugin, best installed via a plugin manager.
Alternatives
screen
should work just as well, I don't think it has as many power features, though. You could also use Neovim / Vim 8 itself as your terminal multiplexer. I haven't yet looked closely into the new terminal features, but I remember that it was suggested that Vim should be able to do lightweight terminal multiplexing, as an alternative for users who don't need the full complexity of tmux
.
Solution 2:
Consider using Alacritty it's like 99% the point is vi navigation of the terminal and having a visual mode.