I know that adding a !
to the end of an option works for some commands, but it doesn't work for cursorbind
. How can I toggle between cursorbind
and nocursorbind
with a keybinding?
2 Answers
You can use a function for it:
function! ToggleCursorbind()
if &cursorbind == 1
set nocursorbind
else
set cursorbind
endif
endfunc
And then make a mapping using your function:
nnoremap <leader>c :call ToggleCursorbind()<CR>
:set cursorbind!
works. Now the issue is that this option is local to the window and needs to be done into several windows in order to see any result. Moreover, it binds line numbers and not cursor positions.
A mapping could be
nnoremap <silent> <leader>whatever :<c-u>set cursorbind!<cr>:set cursorbind?<cr>
:set cursorbind!
toggles the option correctly for me. Note that to see an effect you have to setcursorbind
in at least two windows.