如何使用 Vim 8.1的新终端/termpack 支持滚动终端?

我喜欢 Vim 8.1提供的新终端支持,而且我喜欢将向上/向下映射到终端,这样您就可以选择以前的命令。然而,我怎样才能在终端机上上下下滚动呢?目前,在我的 GDB 程序输出窗口中,我看到如下字符:

[ A ^ [[ A ^ [[ A ^ [ A ^ [ A ^ [ B ^ [ B ^ [ B ^ [ D ^ [ D ^ [

在终端窗口中,它只是在先前的命令之间移动。

18245 次浏览

You have to switch to 'Terminal-Normal mode' with Ctrlw, N (that's Ctrl-w, capital N). Then you can use the usual Vim commands to move around, cut, copy and paste.

Once finished, press either i or a to resume using the terminal as before.

I do this:

tnoremap <c-b> <c-\><c-n>

And then <C-b> whenever I need to scroll back up, using gg to go all the way up, then G to come back down, (or <C-F> for page by page). I press 'i' or 'a' from any page to enter commands in the shell. Simplicity itself.

If you are using neovim, press Ctrl + \ followed by Ctrl + n to enter normal mode in a terminal.

The help (:help terminal-input) says the following:

In this mode all keys except <C-\><C-N> are sent to the underlying program. Use <C-\><C-N> to return to normal-mode. CTRL-\_CTRL-N

Also, if you do this often, I recommend mapping it to something more convenient, like a double tap of Escape:

tnoremap <Esc><Esc> <C-\><C-n>

(That way you can still use programs in the command line, that require escape to retain it's original functionality, since if you don't press anything else, it will just send a regular escape event after your defined timeout length.)