0

In my previous question How to toggle case of word under cursor in vi mode in bash?, I have asked how to make word under cursor upper. The command for that is upcase-word. But unfortunately, that is only for uppering from start of word, to its end. I would like to it the other way and upper from end of word to the start. An example (suppose brackets [] as cursor position)

1)bla bla someword[]

2)bla bla [S]OMEWORD

In vi editor, I can achieve this with this: :inoremap uu <esc>viwUea So I have tried to it in .bashrc like this

-set o vi
bind '"uu":"\eB"upcase-word'

That is, I am trying to make regular movement B to the end of word and then apply the command upcase-word, But I have no clue how to sting them together. I now it would work separately (e.g. this work - bind '"jk":vi-movement-mode', but stringing movements and comands does not. Is it possible?

1

So I came up I need to first bind command to some key. In my case I needed to have shortcut for upcase-word.

1) bind "\C-p":upcase-word
2) bind '"uu":"\eBi\C-pa"'

The important part here is the usage of the mapped command in \C-p (it could be to any other sequence). Once the command is mapped, you are freely able to use it in any part of your vi-movement sequence, but here is also important to mentioned about the mode you are in. Because the command is mapped in insert mode, you have to use it also in insert mode. That is, in my movement sequence (the second command), I firstly exit insert mode (by \e), I do what I need to (move to the end of current word), but i MUST enter to insert mode again (by i), only after that you can use your command shortcut. So it is kinda two-step process. Hope it helps someone else.

| improve this answer | |

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.