0

In vi mode in bash, There is no such thing as toggling case. The only key to toggle until the line is <PageUp> key (as I by chance touched it). And according to this answer How to map PageDown and PageUp Keys to function normally the sequence xterm sends for <PageUp> is this

If you access a Linux computer using an xterm emulator such as Putty, your PgUp key sends four characters Escape [ 5 ~ to the Linux system.

I have tried it on my shell, and it really does work. So the xterm accepts these sequences. So I have tried to add to by .bashrc this:

set -o vi
bind '"uu":"\eB\e[5~a"'

The important part is \e[5~ - which is the <PageUp> key. But despite working in cmd, it does not in .basrc, why so?

0

This isn't working for you because you're trying to emulate the effect of essentially typing those characters into bash. When you do that, you trigger some set of keybindings that makes bash capitalize the word. However, binding those keys as a macro doesn't have the same effect.

Fortunately, there is an operation you can use to upper case a word: upcase-word. So your keybinding should look like the following:

set -o vi
bind -m vi-command '"uu":upcase-word'

That will map the uu sequence to capitalize the word when in command mode. You wouldn't want to map it in insert mode, because then you'd be unable to type uu. To see a list of all the operations you can map, use bind -l.

| improve this answer | |
  • Well the purpose is to map it in inser mode, I could type uu slowly and not trigger the shortcut, but having to enter a command mode and after I can make upper case is not effective for me – Herdsman Apr 17 at 11:53
  • So I have another problem. The upcase-word binding does upper but from the start word to the end. But I would prefer from the end, to the star (backward upper), I have tried bind '"uu":"\eB"upcase-word - but that does not work. How can I string bindings? That is for the first time, I would get beck to the end of word by regular command movement (\e and B), and then use the command to make the word upper. But how to achieve that? – Herdsman Apr 17 at 12:39
  • You can't use escape sequences here, since the values are not key strokes, but readline commands. What you want to do here is run two commands, which are vi-backward-word and upcase-word. You can do this by using a shell function as outlined in this answer. Also, if you want it in vi Insert mode, then use vi-insert instead of vi-command. – bk2204 Apr 17 at 19:39
  • I did it this way - superuser.com/questions/1542852/…. It is basically splitted binding in two commands, but the solution the link suggest - of function is more readable. – Herdsman Apr 17 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.