Synonym for Vim CTRL-A normal mode?

I came to the conclusion that <C-a>in normal mode Vim should not only increase numbers, but also translate Booleans. It makes sense, if you think trueand falseintegers modulo 2.

So, I downloaded a great script to do a hairy job 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, it nnoremapdoesn’t get to the check inside functions. I get recursive behavior if my cursor is not in words trueor false.

At this point, I swear a lot why Bram didn't pick a great idea from Emacs, that everything should be functions and key bindings that can be freely set. Then I could just check the function for <C-a>and call it in that function. But no, I can’t find such a function, and the phrases execute "normal foo"seem to be the idiom of Vim.

Any suggestions on how I could make it <C-a>so that

  • Toggle boolean when cursor is over word trueorfalse
  • Return to inline <C-a>behavior

Help rate!

+5
source share
2 answers

change

execute "normal \ <Ca>"
to:
normal! ^ A

you can get ^ A by running

<Cv> <Ca>
in normal mode

"!" " "

+9

:help :normal

:norm[al][!] {commands}     
...
If the [!] is given, mappings will not be used.
....

,

nnoremap <C-a> :call NewCA()
+6

All Articles