Vim UltiSnips Snippet 自动首字母大写

发布时间: 2020-09-30 15:06:53 作者: 大象笔记

场景

定义一个变量,自动生成类的定义,而类的首字母自动大写。

UltiSnips 的示例配置

当前单词首字母大写

Demo: Uppercase one character
------------------- SNIP -------------------
snippet title "Title transformation"
${1:a text}
${1/\w+\s*/\u$0/}
endsnippet
------------------- SNAP -------------------
title<tab>big small ->
big small
Big small

整句所有单词首字母大写

Demo: Uppercase one character and global replace
------------------- SNIP -------------------
snippet title "Titlelize in the Transformation"
${1:a text}
${1/\w+\s*/\u$0/g}
endsnippet
------------------- SNAP -------------------
title<tab>this is a title ->
this is a title
This Is A Title

使用方法,第一种即可

${1/\w+\s*/\u$0/}

小写第一个字母呢

${1/\w+\s*/\l$0/}

规则

   \u   - Uppercase next letter
   \l   - Lowercase next letter
   \U   - Uppercase everything till the next \E
   \L   - Lowercase everything till the next \E
   \E   - End upper or lowercase started with \L or \U
   \n   - A newline
   \t   - A literal tab

参考

我是一名山东烟台的开发者,联系作者