Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synonym for Vim's normal mode CTRL-A?

Tags:

vim

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 true or false
  • Fall back to built-in <C-a> behaviour otherwise

Help appreciated!

like image 299
mike3996 Avatar asked Jan 29 '11 14:01

mike3996


1 Answers

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"

like image 106
kTT Avatar answered Sep 30 '22 20:09

kTT