tags:

views:

176

answers:

5

Instead of delete the word and retype all the letters once again with opposite case, I'd like to find some smart way in vim to solve the problem . Need your help, thanks in advance .

+5  A: 

It's

g~iw

with the cursor on the word.

Key:

  • g flag (I couldn't find a good reference for this...)
  • ~ toggle case; alternatively use U for to-upper or u for to-lower
  • iw selects the Inner Word, i.e. the word that the cursor is on; ip selects the Inner Paragraph

See Michael Jakl's Vim Introduction and Tutorial - concise and has some nice graphical explanations.

martin clayton
@martin : thanks for your help , it works . but could you explain your command a little, then we can learn more from this topic .
Haiyuan Zhang
`g~`: This changes the case of whatever text-motion comes next. `iw` is the text motion for "inner-word", so `g~iw` changes the case of what vim defines as a word (pretty much what english defines as a word). enter `:help motion` for more info in vim.
Bryan Ross
+3  A: 

You can select the word with visual mode (viw) and press ~, it switches case for all letters in the word.

kemp
+3  A: 

~ (tilde) key. Should change the case of whatever is under the cursor. Works in insert and visual mode.

prevailrob
+5  A: 

Hi,

you can do this in normal mode: vEU (having the cursor at the beginning of the word or pressing b to move it there)

v - go to visual

E - go to end of the word

U - make the visual selection uppercase

Instead of the U you can do u for lowercase or ~ for case flip.

fikovnik
@nkuyu: I like your answer . very help ,thanks
Haiyuan Zhang
if the cursor is in the middle of a word you can use `viwU` or `viwu`. `iw` means 'the entire word'
Nathan Fellman
+6  A: 

g~ followed by a "motion" will flip the case of the letters.

gU will upper-case them

gu will lower case them

So

g~w will flip the case of the letters to the end of the current word.

guG will lower case the letters to the end of the file

gU$ will upper case the letters to the end of the current line.

bmb
and here i was fussing with individual '~' key presses all this time!
JustJeff