在 Vim 可视模式下转换为小写直到特定的分隔符
Convert to lowercase in Vim Visual mode until specific delimiter
基本上我有一个 yml 文件,我想将密钥转换为小写。
示例如下。
KEY: value
ANOTHER_KEY: another_value
我尝试了 vwu
,它按预期工作,但我想在整个文件中应用。
我还使用 .
(点)多次使用 number & j 应用上述命令。
好的,一种方法是使用 sub-replace-expression
功能。以下命令:
:%s/\(\s*\)\(\w*\)\(.*\)/\= submatch(1) . tolower(submatch(2)) . submatch(3)/
将为每一行匹配 whitespace
word
whatever
,并将其替换为相同的内容,但 word
为小写。我假设您熟悉正则表达式的限制和用法,所以我不会详细说明为什么我要那样做表达式、如何修改它,或者对 [=23 使用它们的限制=] 语言(我认为?)就像这里的 yaml
,但是 :s
命令中的 \=
标记可能非常漂亮。
另一种可能的方法:
:%norm! guiw
% ................. the whole file
norm! .............. in normal mode please
gu ................. make {motion} text lowercase
iw ................. inner word
也可以是:
:%norm! gut:
t: .............. until :
基本上我有一个 yml 文件,我想将密钥转换为小写。
示例如下。
KEY: value
ANOTHER_KEY: another_value
我尝试了 vwu
,它按预期工作,但我想在整个文件中应用。
我还使用 .
(点)多次使用 number & j 应用上述命令。
好的,一种方法是使用 sub-replace-expression
功能。以下命令:
:%s/\(\s*\)\(\w*\)\(.*\)/\= submatch(1) . tolower(submatch(2)) . submatch(3)/
将为每一行匹配 whitespace
word
whatever
,并将其替换为相同的内容,但 word
为小写。我假设您熟悉正则表达式的限制和用法,所以我不会详细说明为什么我要那样做表达式、如何修改它,或者对 [=23 使用它们的限制=] 语言(我认为?)就像这里的 yaml
,但是 :s
命令中的 \=
标记可能非常漂亮。
另一种可能的方法:
:%norm! guiw
% ................. the whole file
norm! .............. in normal mode please
gu ................. make {motion} text lowercase
iw ................. inner word
也可以是:
:%norm! gut:
t: .............. until :