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
true
or false
<C-a>
behaviour otherwiseHelp appreciated!
change
execute "normal \<C-a>"to:
normal! ^A
you can get ^A by running
<C-v><C-a>in normal mode
the "!" at the end of normal say "use default mapping"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With