Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I scroll through a terminal using Vim 8.1's new terminal/termpack support? [closed]

Tags:

vim

I love the new terminal support that Vim 8.1 offers and I like that up/down are mapped to the terminal, so that you can select prior commands. How can I scroll up and down the terminal however? Currently, in my GDB program output window I see characters like this:

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

And in the terminal window it just moves between prior commands.

like image 957
dromodel Avatar asked May 25 '18 18:05

dromodel


People also ask

How do I scroll in Vim?

You can make Vim scroll the text using the shifted up/down arrows by mapping Shift-Up to Ctrl-Y and Shift-Down to Ctrl-E. Shift-Down will then scroll down (like moving a scroll-bar down, or like moving a cursor at the bottom of a window down), and Shift-Up will then scroll up (like moving a scroll-bar up, etc).

How do I scroll down in terminal?

And to scroll down in the terminal, use Shift + PageDown. To go up or down in the terminal by line, use Ctrl + Shift + Up or Ctrl + Shift + Down respectively.

How do I scroll in terminal without a mouse?

For most users, you should be able to scroll up and down, one line at a time using Shift+UpArrow or Shift+DownArrow. To jump an entire page at a time, try Shift+PageUp or Shift+PageDown. If these commands don't work, it's likely your terminal is using different keybindings.


3 Answers

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.

like image 77
leightski Avatar answered Oct 13 '22 17:10

leightski


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.

like image 38
M.S. Avatar answered Oct 13 '22 17:10

M.S.


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

like image 6
Isti115 Avatar answered Oct 13 '22 17:10

Isti115