How to change the first two uppercase characters on each line to lowercase in Vim?
I have the follo开发者_运维百科wing text:
HELLO TO STACKOVERFLOW
WELCOME TO STACKOVERFLOW
I want the text to be changed as follows:
heLLO TO STACKOVERFLOW
weLCOME TO STACKOVERFLOW
How can I do that in Vim?
Highlight a visual block for the first two colums with CTRL-V

Enter gu or u to downcase the selected text, gU or U to upcase.

While @Jin provided a good answer for interactive use, here's a way to do it in scripting:
to run to every line of the buffer:
:%normal 0gu2l
or you can specify a line range where to apply the command. This will apply for lines 4 and 5:
:4,5normal 0gu2l
In normal mode:
- if
startoflineis set (:verb set sol?will tell you) you can use:lguCTRL-VG.
Detail :lgoes to next characterguis themake lowercaseoperator, expecting a motionCTRL-Vspecifies that the motion is blockwiseGgoes to first column in last line.
- if
startoflineis not set, thenguCTRL-VGl.(lgoes to next character, and.repeats the same command).
For changing to uppercase change gu with gU, for switching case ensure that tildeop is set and use ~ instead.
In addition to answers given by @Benoit, @Jin and @progo:
:%s/^../\L&\E/
see :help sub-replace-special
You can use the substitution
:%s/.*\%3c/\L&
which takes advantage of the \%c search pattern atom matching the
character at a specific column on a line. Using that atom you can
easily adjust the pattern to match whatever number of first characters
on a line.
加载中,请稍侯......
精彩评论