Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 944
P Shved Avatar asked Mar 18 '10 10:03

P Shved


People also ask

How do you change to uppercase in Vim?

Visual select the text, then U for uppercase or u for lowercase. To swap all casing in a visual selection, press ~ (tilde). Without using a visual selection, gU<motion> will make the characters in motion uppercase, or use gu<motion> for lowercase.

How do I change text to uppercase?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

How do you change to uppercase in vi?

First press v or V then move to select text. If you don't select text, pressing U will undo all changes to the current line. Change the current line to uppercase (same as VU ). Change current word to uppercase.

What Vim command can you use to flip the case of a single letter lower case to upper case vice versa?

Switch case You can switch the case of the alpha character underneath your cursor in vi the tilde key ( ~ ). Doing so shifts from lowercase to uppercase and vice versa.


1 Answers

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.

like image 94
DrAl Avatar answered Jan 03 '23 13:01

DrAl