1

I've added this script to my vimrc file

command! EnableMouse :call EnableMouseFunction()
function! EnableMouseFunction()
    let command = ":set mouse=a"
    exe command
endfunction

So, ... what is the method to unset mouse in vim?

2 Answers 2

6

You don't need anything that complex

set mouse=a
" and
set mouse=

are enough.

You can even define your command to be

:command! ToggleMouse exe 'set mouse='.(empty(&mouse)?'a':'')
" Here I use `:exe` because I didn't want to use `:if` in a command definition which would look like:
:command! ToggleMouse if empty(&mouse) | set mouse=a | else | set mouse= | endif
4
  • Your ToggleMouse command is unnecessary. The built-in command :set mouse! will toggle. See :help :set-inv
    – Kevin
    Jan 13, 2017 at 18:44
  • @Kevin, it's not possible in that case. 'mouse' isn't a boolean option. Jan 13, 2017 at 18:56
  • Ah I see; apologies.
    – Kevin
    Jan 13, 2017 at 18:57
  • @kevin. Don't worry. It was a good remark in the general case. Jan 13, 2017 at 21:36
1

The use of the mouse is controlled (as you find out) with the mouse setting. It is activated only if mouse is equal to "something". This something determines when is the mouse used.

To disable the mouse you can simply:

set mouse=

Also in your function, you can call the set command directly:

function! EnableMouseFunction()
    set mouse=a
endfunction

Your Answer

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

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