0

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?

1
  • 3
    How does it not work? :set cursorbind! toggles the option correctly for me. Note that to see an effect you have to set cursorbind in at least two windows. Nov 17, 2020 at 9:27

2 Answers 2

0

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>
0
: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>

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.