25

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?

ErikE
  • 48,881
  • 23
  • 151
  • 196
P Shved
  • 96,026
  • 17
  • 121
  • 165

5 Answers5

34

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.

DrAl
  • 70,428
  • 10
  • 106
  • 108
  • @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`. – DrAl Mar 18 '10 at 11:47
  • Hm, I thought you could also just add a `~` at the beginning to take care of the character under the cursor, but that resets the mark. Ah well. – Mark Reed Jan 06 '15 at 16:18
  • For a single word, I like to use vbU which has the same result as v`[U (for a single word) but requires less keystrokes and easier key combinations too – arcseldon Dec 21 '15 at 15:22
8

You can also use the "inner word" motion along with gU

After typing a word press <Esc> and type gUiw. This should work without having to switch to visual mode.

dvvrt
  • 599
  • 7
  • 7
  • 1
    See vim documentation: `:help gU`. `gU` converts the character selected by motion `iw` (inner word) to upper case. – dvvrt Aug 28 '13 at 12:57
  • So, how to make an inner word lower case? I tried `gLiw` and `gliw` but failed. – Zen Mar 03 '15 at 04:10
  • 1
    I find the answer myself. To make a word lower case, you use `guiw`, to toggle the case of the word, using `g~iw` – Zen Mar 03 '15 at 04:17
8

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,092
  • 2
  • 20
  • 28
5

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
  • 8,232
  • 9
  • 43
  • 54
1

Sublime Text Vintage Mode

For those using Vintage Mode in Sublime Text.

Uppercase: g U

Lowercase: g u

Swap case: g ~

More info here.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245