Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to enable the mouse wheel for scrolling like ^e and ^y do. I don't want clicking in a buffer to move the cursor though, so :set mouse=a does not help me.

Reason is that I have a bunch of gui windows open (web browser, chat etc) and click to focus vim, but if I click inside the buffer it moves the cursor to where I clicked. I also like to use the mouse wheel for scrolling because I find it faster than ^e and ^y, and easier to keep track if where I am that ^d and ^u or <pgdn> and <pgup>.

Is there a way to enable the mouse support for scrolling, but disable cursor position change when clicking?

Thanks!

share|improve this question
up vote 1 down vote accepted

You can selectively disable mouse buttons by mapping them to <nop>. For example, to disable the left mouse button:

:nmap <LeftMouse> <nop>
:imap <LeftMouse> <nop>
:vmap <LeftMouse> <nop>

If you also want to ignore double clicks:

:nmap <2-LeftMouse> <nop>
…

See:

:help gui-mouse-mapping
:help map-overview
share|improve this answer
1  
Great, just what I was looking for. Any chance it could still allow window/tab selection though (without changing cursor position)? – Matthew Oct 30 '12 at 20:08
    
I can't think of a way to do that, but I won't say it can't be done. – Heptite Oct 30 '12 at 21:10

You must log in to answer this question.

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