如何将Vim中的所有文本转换为小写?这可能吗?


当前回答

我有一个类似的问题,我想使用“:%s/old/new/g”,但最终使用了两个命令:

:0
gu:$

其他回答

使用此命令模式选项

ggguG


gg - Goto the first line 
g  - start to converting from current line    
u  - Convert into lower case for all characters
G  - To end of the file.

If you really mean small caps, then no, that is not possible – just as it isn’t possible to convert text to bold or italic in any text editor (as opposed to word processor). If you want to convert text to lowercase, create a visual block and press u (or U to convert to uppercase). Tilde (~) in command mode reverses case of the character under the cursor. If you want to see all text in Vim in small caps, you might want to look at the guifont option, or type :set guifont=* if your Vim flavour supports GUI font chooser.

剥猫皮的方法有很多……这是我刚刚发布的方法:


:%s/[A-Z]/\L&/g

大写字母也是一样:


:%s/[a-z]/\U&/g

我更喜欢这种方式,因为我一直在使用这种结构(:%s/[pattern]/replace/g),所以它更自然。

类似于mangledorf的解决方案,但更简短,对外行更友好

: % s / . * \ l / g

如果您在某种Unix系统下运行

:0,$!tr "[A-Z]" "[a-z]"