I came to an idea that <C-a> in Vim’s normal mode should not only increase numbers but toggle booleans. It makes sense if you consider true and false as integers modulo 2.
So, I downloaded an excellent script to do the hairy work and wrote a new definition for <C-a>:
fun! NewCA()
let cw = tolower(expand("<cword>"))
if cw == "true" || cw == "false"
ToggleWord
else
" run the built-in <C-a>
execute "normal \<C-a>"
endif
endfun
command! NewCA :call NewCA()
nnoremap <C-a> :NewCA<cr>
But as it happens, nnoremap doesn’t go as far as to check inside functions. I get recursive behaviour if my cursor is not on words true or false.
In this point I swear a lot, why didn’t Bram go pick an excellent idea from Emacs, that everything should be functions and key bindings freely setable. Then I just could check the function for <C-a> and call it in that function. But no, I can’t find such a function, and the execute "normal foo" phrases seem to be the Vim idiom.
Any suggestions on how I could make <C-a> work such that
- Toggle booleans when the cursor is over a word
trueorfalse - Fall back to built-in
<C-a>behaviour otherwise
Help appreciated!
change
to:
you can get ^A by running
in normal mode
the “!” at the end of normal say “use default mapping”