Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vim: How can I disable the mouse in Operator-Pending Mode?

I have a problem: When I initiate Operator-Pending Mode with d or c and I click on the active window, the mouse click acts as a motion. For example, I can position my cursor at the start of a paragraph, press d, then click on a word at the end of the paragraph and Vim will delete from the cursor position to the end of the paragraph. I would like to disable this feature to prevent accidental mouse clicks.

I have added the following in my .vimrc, which tells Vim to enable the mouse only in Normal Mode and Visual Mode.

set mouse=nv

However, this does not work. I can enter Operator-Pending Mode and still use a mouse click as the motion. Is it possible to tell Vim not to accept mouse clicks for motions in Operator-Pending Mode?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

:help 'mouse' won’t help, here, so you can set it to a or any desired value.

You could disable the left mouse in operator-pending mode, though:

onoremap <LeftMouse> <Nop>

which prevents mouse clicks motions in operator-pending mode. Note that, with that mapping, a mouse click is not considered as a motion anymore but it also sort of "breaks out" of operator-pending mode, which may or may not be a problem.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading