使用 Vim 将选择中每个单词的首字母大写 [英] Capitalize first letter of each word in a selection using Vim

查看:19
本文介绍了使用 Vim 将选择中每个单词的首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Vim 中,我知道我们可以使用 ~ 将单个字符大写(如 这个问题),但是有没有办法使用 Vim 将选择中每个单词的第一个字母大写?

In Vim, I know we can use ~ to capitalize a single char (as mentioned in this question), but is there a way to capitalize the first letter of each word in a selection using Vim?

例如,如果我想改变这个

For example, if I would like to change this

hello world from stack overflow

Hello World From Stack Overflow

我应该如何在 Vim 中做到这一点?

how should I do it in Vim?

推荐答案

您可以使用以下替换:

s/<./u&/g

  • < 匹配单词的开头
  • . 匹配单词的第一个字符
  • u 告诉 Vim 将替换字符串 (&)
  • 中的以下字符大写
  • & 表示替换左侧匹配的内容
  • g 表示替换所有匹配项,而不仅仅是第一个
    • < matches the start of a word
    • . matches the first character of a word
    • u tells Vim to uppercase the following character in the substitution string (&)
    • & means substitute whatever was matched on the left-hand side
    • g means substitute all matches, not only the first
    • 这篇关于使用 Vim 将选择中每个单词的首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆