Reputation: 187
I would like to enable or disable mouse support in vim with only one key (in my case F7). It should work in command mode insert mode. I have this in my .virmrc:
set mouse=
nnoremap <F7> :set mouse=a <CR>
inoremap <F7> <C-o> :set mouse=a <CR>
but this does not work. I also want to switch cursorline
on and off in both modes. For this I have this in my .vimrc
set nocursorline
nnoremap <F2> :set cursorline!<CR>
inoremap <F2> <C-o>:set cursorline!<CR>
Cursorline works well, mouse support does not. Why?
Upvotes: 0
Views: 280
Reputation: 56687
The !
modifier in your cursorline example is why it is working. That tells Vim to toggle or invert the current value. It only works for boolean (true/false) settings.
From :help :set
:
:se[t] {option}!
or
:se[t] inv{option}
Toggle option: Invert value. {not in Vi}
In your mouse
case, you'll need something a little more intelligent.
function ToggleMouse()
if &mouse == 'a'
set mouse=
echo 'Mouse mode OFF'
else
set mouse=a
echo 'Mouse mode ON'
endif
endfunction
nnoremap <F7> :call ToggleMouse()<CR>
inoremap <F7> <C-o>:call ToggleMouse()<CR>
Upvotes: 1