tags:

views:

355

answers:

3

Use case: I've just entered insert mode, and typed some text. Now I want to make it uppercase.

It can be done via gUmotion. However, I can't find the motion over the text entered in the recent input session. It's somewhat strange and the concept of such motion is buggy (where to move if you've deleted text, for example?), but it may solve my problem.

Or, are there other ways of making uppercase the text you've recently inputted?

+6  A: 

Type the word in the lower case in the vim.

Then press Esc key.

Then move the cursor to starting character of the typed words.

Then press the ~ key.

It will replace the lower case to upper case.

If the input is upper case it will replace the lower case.

muruga
+2  A: 

I simply select the text in visual mode and use ~ to change the case, U to uppercase or u to lowercase the selected text.

Edit: See comments below.

Waseem
Note that `~` will make upper case characters lower case. `U` is better in this case: `:help v_U`
Al
To do 3 chars you can do "esc v l l l ~"
Johan
+12  A: 

The motion you're looking for is:

`[

(backtick, open-square-bracket). To do a simple motion, you'd use:

gU`[

However, you'll find that the last character probably won't be included due to the way the motion works (I could be wrong). A simple solution would then be to do:

v`[U

Which is to say "go to visual mode, select from the current position to the start of the last changed text, make it upper case". For more information, see:

:help '[
:help mark-motions

Note the difference in :help mark-motions between a backtick and a single-quote.

Al
Hm, doing this through visual mode requires the same amount of keystrokes....
Pavel Shved
@Pavel: Yes, but it has the advantage of working! Try inserting `hello` in the middle of a word and then pressing escape followed by the simple motion approach in my post and you'll get `HELLo`. If you use the visual one, you'll get `HELLO`.
Al
@AI, that's what I meant :-)
Pavel Shved