如何在VIM中设置初始上限?
在 VIM 中,将文本单词更改为使用大写或小写确实很容易:
# in visual mode
# change word to uppercase
gUw
# change word to lowercase
guw
是否有一种简单的方法来修改单词以使用首字母大写?
In VIM, it's really easy to change a word of text to use uppercase or lowercase:
# in visual mode
# change word to uppercase
gUw
# change word to lowercase
guw
Is there a simple way to modify the word to use initial caps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
假设光标位于单词的开头,请使用
(如果单词全部小写)或
显式将第一个字母设为大写,其他字母设为小写。
它与您使用的相同,只是您使用
l
(一个符号动作)而不是w
(文字动作)。如果光标位于单词中间的某个位置,请在上面的命令前面添加
b
(转到单词的开头)。如果您经常使用它,您可以映射一些键来执行此操作。
Assuming cursor is at the beginning of the word, use
(if the word was all-lowercase) or
to explicitly make the first letter capital and other lower case.
It's the same that you used, only instead of
w
(word motion) you usel
(one symbol motion).If the cursor is somewhere in the middle of the word, prepend
b
(go to the beginning of the word) to the commands above.You can map some key to do this if you use it often.
我建议使用您想要的任何运动命令移动到单词的开头,然后按 ~。此行为受
tildeop
选项影响,请参阅:help ~
和:help tildeop
了解更多信息。I'd suggest moving to the beginning of the word with whatever motion command(s) you want, then pressing ~. This behavior is affected by the
tildeop
option, see:help ~
and:help tildeop
for more info.根据您的用例,以下任何一种方法都可能有效。
~
切换光标下字母的大小写。:s/\<\(\w\)\(\w*\)\>/\u\1\L\2/
搜索单词,大写第一个字母,其余小写。guiwgUl
将光标所在的单词小写,然后将第一个字母大写。Depending on what your use-case is, any of the following may work.
~
to toggle the case of the letter under your cursor.:s/\<\(\w\)\(\w*\)\>/\u\1\L\2/
to search for a word, upper-case the first letter, and lower-case the rest.guiwgUl
to lower-case the word your cursor is on and then upper-case the first letter.如果您在单词上:
如果您在单词的开头:
解包:
b
返回一个单词(或到您所在单词的开头),gU
在移动时大写,l
向右移动一个字符(这将是单词中的第一个字母)。If you're on the word:
If you're at the beginning of the word:
Unpacking that:
b
goes back one word (or to the beginning of the word you're on),gU
upcases over movement,l
moves right one character (which will be the first letter in the word).旁注:
我有一个插件 (不过,这不是它的主要目的)能够在驼峰式大小写、下划线分隔的单词等之间转换名称。将光标移到标识符上,然后输入
:NameConvert lower_camel_case
例如(命令支持完成(
、
)以显示所有可能的命名方案)要安装它,您需要 lh-dev 和 lh-vim-lib。
Side note:
I have a plugin (well, it's not its main purpose though) that is able to convert names between camel case, underscore separated words, etc. Move the cursor on an identifier, and type
:NameConvert lower_camel_case
for instance (the command supports completion (<tab>
,<c-d>
) to display all the possible naming schemes)To install it, you'll need lh-dev, and lh-vim-lib.
有一个函数 toupper 可以用来进行转换。即使在替代中你也可以使用它。就像查找所有句子开头,并将第一个字符转换为大写,如下所述: 搜索并替换
There is a function toupper which you can use to make conversion. Even in substitution you can use that. Like find all sentence beginnings, and convert the first character to upper case, as explained here: search and replace