0

I heard that there is no internal function to call when typing a key combo in vim, unlike emacs. So I want to repurpose Ctrl-A to ^ (like, nnoremap < C-A> ^); however, the original function of Ctrl-A is also attractive, so I want to map it to some other keys, say Ctrl-S. How can I do this the vim way?

This question might have been asked but I searched around and did not find anything close. Thanks in advance.

PS: the stupid vim-emacs war is spamming everywhere and nowhere can i find a real solution that makes a desired feature to work in another environment.

eafit
  • 468
  • 4
  • 7
  • Please clarify your post. Do you mean you want to bind keys in Emacs or in Vim? What functions/features are you trying to bind? – Dan Sep 18 '14 at 17:56
  • 2
    no matter which editor you use, try to get used to its keys. map `ctrl-a -> ^` in vim is not good idea, you can map `c-a a to do number+1` however, when you are in screen, tmux (with c-a as prefix), you have to press `ctrl -a a a` to do number+1. And you have to map `ctrl-k, ctrl-f, ctrl-e,ctrl-w ....` then just use emacs, hope you don't map `hjkl` in emacs. – Kent Sep 18 '14 at 19:31
  • oh, speaking of key confusion, most times trying to copy something on mac ends up closing that window :-| – eafit Sep 19 '14 at 14:55

1 Answers1

2

The following should do:

nnoremap <C-A> ^
nnoremap <C-A>A <C-A>

This works because the noremap tells vim to do not apply any other mapping, thus the rhs of the second mapping above is the default <Ctrl-A>.

You will notice that the first mapping will take a delay to execute, because vim waits a while to allow you to type the second mapping. Vim-FAQ 20.16 may help if this bothers you.

But I'd advice against changing the default mapping because, as explained here, vim has many default mappings that may seems silly when you start using it. When you understand it better you will have a hard time finding another key to map it or to get used to the old/default mappings.

Community
  • 1
  • 1
mMontu
  • 8,983
  • 4
  • 38
  • 53
  • it did not work for me ... I had vim 7.3. Also, speaking of the ideal key cliche, ^ is really unapproachable for its frequency; or i guess i should really get used to 0w combo? – eafit Sep 19 '14 at 15:09
  • It should work on vim 7.3. Without further details it is kind of hard to provide any help. – mMontu Sep 19 '14 at 15:37
  • even if i just have nnoremap or nmap , nothing happens when i press C-S. This is the only line in .vimrc and there is no .vim folder. i am using mac if that might be a problem. – eafit Sep 19 '14 at 16:22
  • 1
    Try to narrow your problem: is it caused due to the 'from' or the 'to'? E.g.: try mapping to something else, as `nnoremap iabc` to enter insert mode and insert 'abc'; or try mapping some other key to . Also check the Vim-FAQ, in special entries 20.4 and 20.5 – mMontu Sep 19 '14 at 20:03
  • i think this is the issue: firstly a should be mapped rather than A and secondly does not mean Ctrl-S. But otherwise, your solution works. and the comment was pretty good for debugging. Thanks! – eafit Sep 19 '14 at 21:45