Tuesday, November 2, 2010

Re: Using Bash in Vi mode. How to map keys?

Reply to message «Re: Using Bash in Vi mode. How to map keys?»,
sent 15:40:29 02 November 2010, Tuesday
by aleCodd:

> I still have 2 problems with that, first i don't know how to "submit" the
> command back to bash after editing the command on vim, and second its
> really over the top, to switch back and forth between bash and vim for
> every single command.
>
> another problem im struggling now, is to find out what is the equivalent to
> ":noremap" in when binding keys in .inputrc for bash.
>
> I mean, sure you can bind the following:
> "a":"b"
> but how do you bind:
> "a":"aa"
> because this will not work because it will enter into an ENDLESS LOOP by
> remapping the 'a' character to itself...
Maybe you should try switching to zsh: its zle (z line editor) is highly
configurable. Though it does not have an equivalent to `noremap', you could bind
keys to functions: your example could be written like that:

function _-ins-aa() { LBUFFER+=aa }
zle -N ins-aa _-ins-aa
bindkey a ins-aa

Not as obvious as `noremap a aa' (or `bindkey -s a aa' that results in ``zsh:
string inserting another one too many times'' error), but it works.

It also has a vi mode and I saw an answer on stackoverflow that explains how to
change prompt when switching from/to `normal' mode:
http://stackoverflow.com/questions/3622943/zsh-vi-mode-status-line (links in
this question are also useful). It looks like bash does not have such option.

No comments: