Gambo
Gambo

Reputation: 5140

How can I turn off "scrolling the history" in iTerm2

I have installed the new iTerm 2. It asked me in a yellow bar at the top if I'd like to enable a mouse feature. Unfortunately, I don't remember the exact sentence anymore.

By accident I approved. Now when I use the scroll wheel on the mouse in iTerm, it doesn't scroll the up anymore, but instead it goes triggers the command history as if I had pressed the up-cursor.

Where I can toggle this option to turn it off again?

Upvotes: 479

Views: 141619

Answers (11)

Gal
Gal

Reputation: 5907

This can happen if you're SSHd to a server and then get booted off of your SSH session.

A quick way to fix this is:

$ reset

Upvotes: 1

tarikakyol
tarikakyol

Reputation: 601

as of 2023 CMD + R gets you out of the Alternate mode

Upvotes: 5

Lynne
Lynne

Reputation: 547

An update in 2022

In Preferences -> Profiles -> Terminal enter image description here

uncheck the

  • "Save lines to scrollback in alternate screen mode" and
  • "Save lines to scrollback when an app status bar is present"

Upvotes: -1

Ortomala Lokni
Ortomala Lokni

Reputation: 62683

If you are trapped in the scrolling history mode, you can escape by running vi and exiting. You can also choose another program that uses the alternate screen and then exit.

Scrolling the history with the mouse wheel should in theory never happen. It happens in practice because sometimes the alternate screen mode is not correctly switched back. The accepted answer solves the problem by deactivating a feature that is useful, namely scrolling in vi, less, ... with the mouse wheel or trackpad. You can keep the option from the advanced preferences:

Scroll wheel sends arrow keys when in alternate screen mode

set to yes. You will sometimes be trapped in the scroll history mode. But if you know how to escape, it's not a problem.

Upvotes: 123

psoo
psoo

Reputation: 101

If you are in a more recent version of MacOS (mine is Monterey 12.0.1) and don't see the "Mouse" option under preferences, you can find this option by going to "Terminal -> Preferences -> Profiles -> Keyboard tab" and then uncheck the box "Scroll alternate screen" as shown in the red box below:

enter image description here

Upvotes: 2

Kyle Smith
Kyle Smith

Reputation: 2332

With iTerm2 you can also hold Option while using the scroll wheel to force window scrolling, in case you do want the wheel to continue to work in vim.

Upvotes: 25

Thomas Dickey
Thomas Dickey

Reputation: 54583

A few terminals, including iTerm2, have a feature where they change the behavior of the wheel mouse when a full-screen program such as vi, or screen or tmux is running. This happens when those programs use the alternate screen, to provide a useful function. Normally, when using the alternate screen in iTerm2, the wheel mouse acts like the scrollbar, scrolling the entire screen up/down. But when this feature is enabled, iTerm2 sends cursor up/down keys, making your command-history change.

As suggested in another comment, select the Preferences menu:

enter image description here

and in that, select the Advanced tab. Scroll down to the Mouse section,

enter image description here

and toggle the entry for

Scroll wheel sends arrow keys when in alternate screen mode

from Yes to No. You will have to restart iTerm2 for the change to take effect. (With iTerm2 v3.1.5 changes take effect without restarting.)

Upvotes: 812

dlamblin
dlamblin

Reputation: 45381

The behavior you're seeing is the expected (and correct) behavior when in the alternate screen. The only problem you have is that you dropped into bash, or whatever, on the alternate screen, possibly while losing a connection or from a killed vim or less. EG you were in less +F /var/log/something and got disconnected.

You see someone has already written that the tput rmcup command will exit to the main screen.

I also went ahead and looked up some terminal control characters. It can be any of: ESC [ ? 1 0 4 9 l or ESC [ ? 1 0 4 7 l or ESC [ ? 47 l (gnu.org/software/screen/manual/html_node/Control-Sequences.html) with a preference to the first.

I'm generally successful in iTerm2 with echo -e '\e[?1049l' I actually don't find rmcup any easier to remember, restore memory of console up?.

Upvotes: 5

otrejni
otrejni

Reputation: 1132

You probably just need to get out of alternate console.

Try: tput rmcup

Upvotes: 73

Stan
Stan

Reputation: 9

I was having this same problem and none of the solutions I read and tried worked. What fixed my problem was turning Secure Keyboard Entry off and now when I use the mouse to scroll it in ssh and in terminal mode on macOS 10.13 it works like I expect it too!

Upvotes: 0

Idiot
Idiot

Reputation: 221

Preferences:Advanced:Mouse:Scroll wheel sends arrow keys when in alternate mode

Upvotes: 22

Related Questions