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?

up vote 6 down vote accepted

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
  • Your ToggleMouse command is unnecessary. The built-in command :set mouse! will toggle. See :help :set-inv – Kevin Jan 13 '17 at 18:44
  • @Kevin, it's not possible in that case. 'mouse' isn't a boolean option. – Luc Hermitte Jan 13 '17 at 18:56
  • Ah I see; apologies. – Kevin Jan 13 '17 at 18:57
  • @kevin. Don't worry. It was a good remark in the general case. – Luc Hermitte Jan 13 '17 at 21:36

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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