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...

  • 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 '19 at 19:47

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

set mouse=
set ttymouse=
| improve this answer | |
  • I did not know about ttymouse, thank you! – James M. Lay Dec 6 '18 at 20:54
  • 1
    +1 for ttymouse, all websites were mentionning mouse but ttymouse was the one I was missing. Thanks ! – KaKi87 Apr 21 at 22:19

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.

| improve this answer | |
  • 5
    Why c and not completely blank? – Rich Nov 1 '17 at 13:27

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.

| improve this answer | |
  • 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

You can use -C flag

vim -C somefile
| improve this answer | |
  • 4
    Welcome to this site @quant2016! Your answer was flagged as low quality because of its length. It would be useful for future readers that you explain why -C is a solution. Note that this flag doesn't only disable the mouse but it sets the compatible mode of vim which has a lot of unattended side effect here, so I think that this should really be mentioned because it could cause more issues than it solves. – statox Aug 4 at 10:08

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.