Enable mouse for scrolling only in Vim in iTerm (MacOSX)

30

11

I'd like to use the mouse in Vim only for scrolling (not to enable other Vim modes or otherwise interact with Vim). Using :set mouse=a seems to be an all or nothing operation, can this be altered? Alternatively can iTerm be made to only pass through scroll events and never click/drag events?

Long Explanation: I use Vim in iTerm a lot and don't use the mouse. However, inertia scrolling with a trackpad is really nice and a great way to peruse large files. I can :set mouse=a and use the trackpad to scroll and it's great. Now when I click however vim enters visual mode and iTerm will not copy selected text. I would like to retain iTerms ability to select and copy text.

I have thought about setting up Vim so that copying in vim will copy in Mac OS X (using pbcopy, I need to do this anyway). This will do the trick when editing local files, but most of the time I'm ssh'd somewhere and editing remote files.

Jonah Braun

Posted 2011-01-27T05:34:55.910

Reputation: 1 407

Answers

44

You could use

:set mouse=nicr

It works only with mouse scroll as I've tested.

Armando Neto

Posted 2011-01-27T05:34:55.910

Reputation: 556

Where do you write :set mouse=nicr? – Naguib Ihab – 2019-04-29T06:14:56.977

3Not quite what I need as while it will scroll in vim, iTerm won't let me select text. I've :set mouse=i so that scroll works in insert mode and iTerm select in normal mode. Close enough, so I'm marking answered. Thanks for the idea! – Jonah Braun – 2011-12-15T21:30:31.203

3That looks like "set the mouse to be nicer" to me. – Kazark – 2012-08-30T17:07:50.970

6

@JonahBraun, iTerm will mouse select with :set mouse=nicr if you hold down option while making the selection. See http://stackoverflow.com/questions/4608161/copy-text-out-of-vim-with-set-mouse-a-enabled

– John Whitley – 2013-03-22T23:58:38.060

18

If you set mouse=a, you can still use Option-click to make iTerm do selection. Not ideal, but it's the best option I've found.

Mike Morearty

Posted 2011-01-27T05:34:55.910

Reputation: 591

3this is the real workable answer. – Zen – 2015-02-15T07:46:51.210

1

I'm not sure about iTerm but this is achievable with Terminal.app.

  • Scrolling in Terminal.app:

http://ayaz.wordpress.com/2010/10/19/using-mouse-inside-vim-on-terminal-app/ (install SIMBL and MouseTerm)

  • Scrolling only:

    1. Go to terminal;
    2. Preference;
    3. 'Settings' Icon;
    4. 'Keyboard' Tab
    5. 'Mouse...' button;
    6. There under 'Send mouse events for:" uncheck "Left click", "Middle click", "Right click".

Done.

LiL

Posted 2011-01-27T05:34:55.910

Reputation: 11

0

You can also set vim env options from command line

For example:

vim -c 'set mouse=a'

So an alternate alias for vim that does it automatically might be:

alias vimmy="vim -c 'set mouse=a'"

Dan Burkhardt

Posted 2011-01-27T05:34:55.910

Reputation: 1

-1

Even better than the accepted answer:

set mouse=a

This allows scrolling and then highlighting gives you a visual block.

ibash

Posted 2011-01-27T05:34:55.910

Reputation: 117

2This enables things other than scrolling. – Kazark – 2012-08-30T17:10:18.220

3Moreover, that is already mentioned in the question. – Kazark – 2012-08-30T17:15:00.510