Mac OS X Terminal: mouse support?

75

25

Is there a native option (ie. without installing extra soft/package/plugins) to enable mouse support in the Terminal app?

Actually, I'm using a lot vim with the option set mouse=a (activating mouse features).

But it seems that Terminal doesn't support all xterm's features.

It appears (after some googling) that Terminal had once the mouse support, but I wonder where did it go.

N.B: I really want mouse support in Terminal, not only for vim, so please, don't suggest MacVim :]

avetis.kazarian

Posted 2010-03-28T08:39:20.440

Reputation: 2 236

What does xterm support that Terminal doesn't? Copy-on-highlight and middle-paste? – Ignacio Vazquez-Abrams – 2010-03-28T08:44:44.800

The mouse reporting. It's the real mouse support. The copy-on-highlight, middle-paste, etc. are not really related to Terminal as far as I know. – None – 2010-03-28T09:25:12.407

2copy-on-highlight and middle-paste ate Terminal related - in that Terminal does not do them - you could try iTerm for those – user151019 – 2010-03-28T09:53:53.993

@Mark: I checked it and liked it. Though Terminal handles far better bold characters. Anyway, thanks. – None – 2010-03-28T11:32:48.383

I still don't understand what you'd expect from mouse support (other than copy/paste, which is supported -- see http://superuser.com/questions/62609/mac-terminal-copy-on-select-like-putty/62659#62659). Like: what do you expect when running ls and then positioning the mouse somewhere in that output?

– Arjan – 2010-03-28T20:33:11.040

2@Arjan: some interactive CLI apps support the mouse; for instance, positioning the text cursor in vim. – ELLIOTTCABLE – 2011-11-21T16:40:57.197

Answers

104

I found the answer!

A friend told me the trick, it's so easy that I'm ashamed.

Just press alt key and click! (with mouse support previously activated in vim)


UPDATE for OSX 10.11 El Capita

Please see Chris Page answer.

avetis.kazarian

Posted 2010-03-28T08:39:20.440

Reputation: 2 236

even when vim has all that magic navigation keys, I still miss the mouse to put the cursor, this answer just allows to select text in block mode. – sites – 2015-01-13T23:05:54.187

1Holy sh*t! I've been using vim in the Terminal for years and never knew this was possible. Best new vim trick I've discovered in a very long time! Thanks. – GMA – 2015-01-29T22:48:32.580

Works for me with iTerm – Anthony – 2015-12-02T01:43:01.217

@AnthonyMayfield: Sure, but we're talking about Terminal here :) – avetis.kazarian – 2015-12-02T16:41:54.053

Note: Option-Click just sends enough cursor up/down/left/right character sequences to attempt to move the cursor to the clicked location. It is unrelated to Mouse Reporting or Xterm mouse events, and it does not matter whether Vim mouse support is enabled. It does not send mouse click events, and you cannot use it to switch panes in an editor like Vim or Emacs. As of OS X 10.11 El Capitan, Terminal supports Mouse Reporting (see my answer for details). – Chris Page – 2016-01-15T02:55:33.970

@juanpastas: “this answer just allows to select text in block mode”. If you Option-Click and release without moving the mouse, it will send cursor-key input to move the cursor. If you find that Option-Click is changing the selection, you're moving the mouse while it is down. Try to click without moving. – Chris Page – 2016-01-15T02:58:24.453

11I’ve been an OS X power user for what feels like half a century, and I never knew this. I am extremely impressed. I wish I could give you a hundred up votes instead of one. – ELLIOTTCABLE – 2011-11-21T16:42:39.083

4Anyway to disable the requirement to use alt? – philfreo – 2012-07-09T13:56:28.990

8It's not the same, for me anyway. Often I click on a character and the cursor ends up somewhere else, sort of near it. It also doesn't work for switching tabs in vim. It also seems not to work so well for switching windows in tmux. – andyortlieb – 2012-07-14T11:35:12.113

1@andyortlieb: that's why I moved to iTerm2. – avetis.kazarian – 2012-07-16T15:04:34.333

2no worky for me. – Mike Graf – 2013-06-06T21:32:42.600

haha nice, this works for me :D – Dzung Nguyen – 2013-09-07T15:44:53.733

23

As of OS X 10.11 El Capitan, Terminal supports Mouse Reporting.

Note that programs that support Mouse Reporting must enable it via escape sequences, and that most programs that support Mouse Reporting must be configured to enable it. For example, in Vim you must execute set mouse=a (usually in your ~/.vimrc file).

Terminal supports reporting three mouse buttons and a scroll wheel. To simulate a button-three press with a two-button device, you can use Command-Right-Click. (Command-Right-Click also performs Edit > Paste Selection when Mouse Reporting is off, so Middle-Click will paste the most-recently selected text whether you're using Mouse Reporting or not.)

When Mouse Reporting is enabled, the Option ⌥ modifier key is mapped to Meta for clicking and scrolling, and is unaffected by the “Use Option as Meta key” Keyboard preference, which only applies to keyboard input.

To temporarily bypass Mouse Reporting and interact with the terminal view, press the Fn modifier key while clicking or scrolling. There is also a View > Allow Mouse Reporting (⌘R) menu item you can use to bypass Mouse Reporting for longer periods of time, or if the modifier key isn't available.

Note that, when enabled, Mouse Reporting supersedes Terminal's existing Option-Click behavior (which sends arrow-key input to move the cursor) and “Scroll alternate screen” behavior. Also, the new Allow Mouse Reporting menu item and the Fn modifier also apply to “Scroll alternate screen” to let you temporarily bypass this behavior.

Chris Page

Posted 2010-03-28T08:39:20.440

Reputation: 2 793

"Allow Mouse Reporting" is the answer for me. iTerm2 had this feature but I just want to use builtin Terminal app for its lightweight. – Kay – 2019-08-13T20:34:58.947

@Kay: I’m glad you like it, but, to be clear, the “Allow Mouse Reporting” menu item does not turn on Mouse Reporting. It is merely a command to let you temporarily interact with the terminal view instead of sending mouse input to the remote program when Mouse Reporting has been enabled. Programs enable Mouse Reporting by sending control sequences to the terminal. – Chris Page – 2019-09-13T03:26:43.987

12

As an alternative to using Alt-click to set the cursor in vi with OS X Terminal, I would like to suggest using iTerm 2:

I wanted mouse support in Terminal vi (Mac OS X 10.7 Lion), but there's no support for scrolling with the scroll wheel. I ended up switching from Terminal to iTerm 2, which supports vi scroll wheel scrolling, and you don't need to hold down alt to set the cursor.

If you don't use some of the more advanced features in Lion's Terminal app, you may be quite happy with iTerm 2.

Edit: To enable mouse support in Vim when using iTerm 2, add the following line to your .vimrc:

:set mouse=a

Steve HHH

Posted 2010-03-28T08:39:20.440

Reputation: 5 590

On MacOS Mojave (10.14) I have no problem using mouse in vim using the OSX Terminal. – gagarine – 2019-05-22T20:40:18.080

How can you scroll down using the mouse wheel? It just goes up the screen buffer, and you can get that in Terminal.app by disabling the use of the alternate screen buffer, e.g. in vim using set t_ti= t_te= in your ~/.vimrc. – Daniel Beck – 2012-07-11T18:26:28.873

I did need to configure :set mouse=a in my .vimrc -- that's the normal way to enable mouse support in Vim, but it seems that mouse input is eaten by Terminal.app. Scrolling up and down in a text file with the scroll wheel seems to work perfectly in iTerm2.app, however. – Steve HHH – 2012-07-11T22:03:27.523

1

It appears that on OS X 10.4 (I'm not sure about 10.5) you can enable mouse support. Open the Terminal, then click on Window Settings. Click Emulation from the drop down list and then check the option "Click to position Cursor".

Joe D

Posted 2010-03-28T08:39:20.440

Reputation: 121

1Actually, there's nothing such as "Window Settings" in Terminal preferences on 10.5 neither on 10.6. All you can to in the "Window" tab is change the background color, scroll size, title and window size. – None – 2010-03-28T09:20:27.000

1It must be only on 10.4 then... – None – 2010-03-28T09:57:30.953

1This isn't exactly mouse support. What this will do is allow you to option click a part of the terminal, and Terminal.app will calculate how many line up/down/left/right characters are needed to move the cursor there, and then type them. Very useful but not what the OP wanted I don't think. – Josh – 2010-04-02T22:27:16.623

1

Note that Mac OS X does have xterm in addition to Terminal.app. I couldn't tell from your question if you were aware of this. But if you have the X11 package installed you can fire up an xterm window and mouse support works just fine.

Josh

Posted 2010-03-28T08:39:20.440

Reputation: 7 540

0

MouseTerm seems to be the perfect SIMBL plugin for those who want decent mouse support in their Mac OS X Terminals. As of May 2013, the latest version (1.0b1 released in Jul 2011) states it adds the following features to OS X's standard Terminal application:

  • Mouse button reporting.
  • Mouse scroll wheel reporting.
  • Simulated mouse wheel scrolling for programs like less (i.e. any fullscreen program that uses application cursor key mode).
  • Terminal profile integration (with preferences dialog).

I'm using tmux and vim with it, and it allows me to not only click (without the option key!) but also scroll and drag inside them with little configuration: e.g., :set mouse=a for vim, and tmux set-window-option mode-mouse on. It's easy to toggle mouse reporting (with a single key combination ⇧⌘M, or from the Shell menu), so there's nothing to lose to have it installed.

(Caveat: Clicking/draging in tmux copy-mode isn't working as I expected, though.)

netj

Posted 2010-03-28T08:39:20.440

Reputation: 31

Another caveat - I have noticed that after I first start Terminal after logging in, the mouse support does not work at all until I quit Terminal and start it again. – Michael – 2013-06-11T15:49:01.620

@Michael: Your symptom sounds familiar to the old SIMBL Issue 13. Updating SIMBL would probably fix that. (0.9.9 or 0.9.9b)

– netj – 2013-06-13T17:28:34.673

tried 0.9.9, didn't work. tried the AppleScript in comment #23, got "Expected end of line but found identifier" (changed "Snow Leopard" to "Lion", but I am running Lion...) – Michael – 2013-07-05T22:24:10.863

also tried 0.9.9b (Patched for Lion), and that doesn't fix it either. still have to restart Terminal before it will accept mouse events. – Michael – 2013-07-05T22:30:35.877

-1

You can set up xterm emulation in advanced preferences, at least in Terminal 2.4 (OS X 10.9.3). This enabled proper mouse support for me.

Tom S

Posted 2010-03-28T08:39:20.440

Reputation: 1

It doesn't work (please be sure to test with vim and tmux). – avetis.kazarian – 2014-07-25T09:30:00.447