如何将 vim 中的特定大写单词大写

How to capitalize specific uppercase words in vim

我们有一个 5000 行的文本文件,其中包含如下文字:

BANKS
BEING AFRAID OF DOGS
This is a SENTENCE.
Just another sentence.
COUNTRY

使用 vim,我只想将所有单词都大写的行中的单词大写(意味着第 3 行和第 4 行应该保持不变)。也就是说,我期望得到的是:

Banks
Being Afraid Of Dogs
This is a SENTENCE.
Just another sentence.
Country

参考Power of g and Switching_case_of_characters.

  1. 将命令应用于仅包含大写字符和 space 的行,即 g/^[A-Z ]*$/
  2. 然后做Title case转换s/\<\(\w\)\(\w*\)\>/\u\L/g

整个命令将是 :g/^[A-Z ]*$/s/\<\(\w\)\(\w*\)\>/\u\L/g