Vim: how to make the text I've just typed uppercase?

P Shved picture P Shved · Mar 18, 2010 · Viewed 8.7k times · Source

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?

Answer

DrAl picture DrAl · Mar 18, 2010

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.