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


当前回答

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.

其他回答

用g~切换大小写“HellO”到“HellO”,然后移动。 大写的“HellO”到“HellO”加上gU然后移动。 小写的“HellO”到“HellO”加上gu然后一个动作。

有关例子和更多信息,请阅读以下内容: http://vim.wikia.com/wiki/Switching_case_of_characters

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),所以它更自然。

我假设你想要小写的文本。解决方法很简单:

ggVGu

解释:

Gg -指向文本的第一行 V -打开视觉选择,在直线模式下 G -转到文件的结尾(此时你已经选择了整个文本) 小写的选定区域

使用此命令模式选项

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.