如何在VIM中设置初始上限?

发布于 2024-09-08 12:37:26 字数 176 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

爱冒险 2024-09-15 12:37:26

假设光标位于单词的开头,请使用

gUl

(如果单词全部小写)或

gUllgue

显式将第一个字母设为大写,其他字母设为小写。

它与您使用的相同,只是您使用 l (一个符号动作)而不是 w (文字动作)。

如果光标位于单词中间的某个位置,请在上面的命令前面添加 b(转到单词的开头)。

如果您经常使用它,您可以映射一些键来执行此操作。

Assuming cursor is at the beginning of the word, use

gUl

(if the word was all-lowercase) or

gUllgue

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 use l (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.

硪扪都還晓 2024-09-15 12:37:26

我建议使用您想要的任何运动命令移动到单词的开头,然后按 ~。此行为受 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.

安稳善良 2024-09-15 12:37:26

根据您的用例,以下任何一种方法都可能有效。

  1. 使用 ~ 切换光标下字母的大小写。
  2. 使用 :s/\<\(\w\)\(\w*\)\>/\u\1\L\2/ 搜索单词,大写第一个字母,其余小写。
  3. guiwgUl 将光标所在的单词小写,然后将第一个字母大写。

Depending on what your use-case is, any of the following may work.

  1. Use ~ to toggle the case of the letter under your cursor.
  2. Use :s/\<\(\w\)\(\w*\)\>/\u\1\L\2/ to search for a word, upper-case the first letter, and lower-case the rest.
  3. guiwgUl to lower-case the word your cursor is on and then upper-case the first letter.
过期以后 2024-09-15 12:37:26

如果您在单词上:

bgUl

如果您在单词的开头:

gUl

解包: b 返回一个单词(或到您所在单词的开头),gU 在移动时大写,l 向右移动一个字符(这将是单词中的第一个字母)。

If you're on the word:

bgUl

If you're at the beginning of the word:

gUl

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).

森林散布 2024-09-15 12:37:26

旁注:
我有一个插件 (不过,这不是它的主要目的)能够在驼峰式大小写、下划线分隔的单词等之间转换名称。将光标移到标识符上,然后输入 :NameConvert lower_camel_case 例如(命令支持完成()以显示所有可能的命名方案)

要安装它,您需要 lh-devlh-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.

顾北清歌寒 2024-09-15 12:37:26

有一个函数 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文