Vim UltiSnips Snippet 自动首字母大写

文章目录

    场景

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

    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
    

    参考

    • https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式