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?



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>


:help gui-mouse-mapping
:help map-overview
  • 2
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.