Reputation: 17517
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!
Upvotes: 7
Views: 2186
Reputation: 25060
From :help :normal
:norm[al][!] {commands}
...
If the [!] is given, mappings will not be used.
....
Also defining a command is not needed, you can directly
nnoremap <C-a> :call NewCA()
Upvotes: 6
Reputation: 1350
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"
Upvotes: 13