85

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 :]

6
  • What does xterm support that Terminal doesn't? Copy-on-highlight and middle-paste? Mar 28, 2010 at 8:44
  • 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.
    – avetis.kazarian
    Mar 28, 2010 at 9:25
  • 2
    copy-on-highlight and middle-paste ate Terminal related - in that Terminal does not do them - you could try iTerm for those
    – mmmmmm
    Mar 28, 2010 at 9:53
  • @Mark: I checked it and liked it. Though Terminal handles far better bold characters. Anyway, thanks.
    – avetis.kazarian
    Mar 28, 2010 at 11:32
  • 2
    @Arjan: some interactive CLI apps support the mouse; for instance, positioning the text cursor in vim. Nov 21, 2011 at 16:40

7 Answers 7

116

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.

12
  • 12
    I’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. Nov 21, 2011 at 16:42
  • 4
    Anyway to disable the requirement to use alt?
    – philfreo
    Jul 9, 2012 at 13:56
  • 8
    It'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. Jul 14, 2012 at 11:35
  • 1
    @andyortlieb: that's why I moved to iTerm2. Jul 16, 2012 at 15:04
  • 2
    no worky for me.
    – Mike Graf
    Jun 6, 2013 at 21:32
30

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.

2
  • "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
    Aug 13, 2019 at 20:34
  • @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
    Sep 13, 2019 at 3:26
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
3
  • 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
    Jul 11, 2012 at 18:26
  • 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
    Jul 11, 2012 at 22:03
  • On MacOS Mojave (10.14) I have no problem using mouse in vim using the OSX Terminal.
    – gagarine
    May 22, 2019 at 20:40
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".

3
  • 1
    Actually, 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.
    – avetis.kazarian
    Mar 28, 2010 at 9:20
  • 1
    It must be only on 10.4 then...
    – Joe D
    Mar 28, 2010 at 9:57
  • 1
    This 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
    Apr 2, 2010 at 22:27
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.

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

4
  • 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
    Jun 11, 2013 at 15:49
  • @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
    Jun 13, 2013 at 17:28
  • 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
    Jul 5, 2013 at 22:24
  • 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
    Jul 5, 2013 at 22:30
-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.

1
  • It doesn't work (please be sure to test with vim and tmux). Jul 25, 2014 at 9:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .