5

I saw completely disable mouse in console vim on Stack Overflow. It sounded like exactly what I wanted, but there the problem was related to Cygwin, so the title was a misnomer.

I want to know how to completely disable all mouse interactions in vim on the console. I don't want scrolling, selecting, clicking, or otherwise looking at the mouse to have any effect within vim.

I like having the mouse in the console, just not when I'm using vim. Is this possible?

I have a laptop with ubuntu installed on it and when I type, occasionally the touch pad mouse decides to randomly click or drag between some random coordinates on the screen, even when I try my hardest not to touch the damned thing. This has the effect of me typing code in the wrong places all the time, and it's getting really old because sometimes it introduces subtle irreversible bugs into my code.

I've been able to get rid of scrolling and visual select using the commands below in my .vimrc, but it still will relocate the cursor when I click.

" disable mouse interactions "
set mouse=nicr
map <ScrollWheelUp> <nop>
map <S-ScrollWheelUp> <nop>
map <C-ScrollWheelUp> <nop>
map <ScrollWheelDown> <nop>
map <S-ScrollWheelDown> <nop>
map <C-ScrollWheelDown> <nop>
map <ScrollWheelLeft> <nop>
map <S-ScrollWheelLeft> <nop>
map <C-ScrollWheelLeft> <nop>
map <ScrollWheelRight> <nop>
map <S-ScrollWheelRight> <nop>
map <C-ScrollWheelRight> <nop>

What else do I need to do?

P.S. I tried set mouse=, but that seems to reenable visual select...

migrated from stackoverflow.com Sep 14 '17 at 12:25

This question came from our site for professional and enthusiast programmers.

  • 6
    set mouse= effectively disables every mouse interaction with Vim, but not with your terminal emulator. Are you sure that "visual select" is Vim's? – romainl Sep 14 '17 at 7:44
  • This could be due to loading a central configuration _after _ loading the config in /etc/vimrc. See my answer here: unix.stackexchange.com/a/506723/194822 – Holger Böhnke Mar 16 at 19:47
7

You should add the following two lines at the end of /etc/vim/vimrc :

set mouse=
set ttymouse=
  • I did not know about ttymouse, thank you! – James M. Lay Dec 6 '18 at 20:54
1

This is only a partial solution at best, but you can globally disable the mouse/touchpad while vim is running with xinput in a shell script:

xinput set-prop $ID "Device Enabled" 0

And then

xinput set-prop $ID "Device Enabled" 1

When you're ready to have the touchpad work again.

Use xinput --list to get the id of your pointing device.

  • This might combine well with the FocusGained and FocusLost autocommand events, though it looks like it there might be some challenge in finding a terminal + Vim setup where those events can be detected. – 8bittree Sep 15 '17 at 0:32
1

This might work if you put it at the end of your .vimrc

set mouse=c

It's probaly not Vim that takes the mouse input, but rather your Terminal-emulator. To disable mouse support on your terminal this might help.

  • 1
    Why c and not completely blank? – Rich Nov 1 '17 at 13:27

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.