38

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

2
  • 7
    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, 2017 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 Mar 16, 2019 at 19:47

4 Answers 4

58

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

set mouse=
set ttymouse=
7
  • 5
    +1 for ttymouse, all websites were mentionning mouse but ttymouse was the one I was missing. Thanks !
    – KaKi87
    Apr 21, 2020 at 22:19
  • 2
    Crazy thing is that, when inside the editor, issuing :set mouse-=a works just fine. However, within the vimrc file only set ttymouse= does the trick. Why is that? Anyway: Thanks for the ttymouse from me as well. Dec 29, 2020 at 19:01
  • 1
    set ttymouse= breaks the auto resize of vim when I resize my terminal emulator (terminator)
    – on8tom
    Oct 6, 2021 at 12:08
  • @on8tom did you try with another terminal emulator? Maybe it is a bug on their side? Oct 6, 2021 at 12:46
  • the same goes for gnome-terminal but setting set mouse= in /usr/share/vim/vim82/defaults.vim fixes it. but that also disables all mouse whithout setting set ttymouse=
    – on8tom
    Oct 6, 2021 at 12:58
3

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
  • 7
    Why c and not completely blank?
    – Rich
    Nov 1, 2017 at 13:27
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.

1
  • 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, 2017 at 0:32
1

You can use -C flag

vim -C somefile
1
  • 5
    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, 2020 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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