regexvimultisnips

Regex for extract first character of word (Ultisnips)


I am attempting to use the Ultisnips Vim plugin to replace a word with its first character, transformed to lowercase (anong other things that aren't relevant to the question). For illustration, I wish to write a snippet

snippet 
$1 ${1/ WHAT TO PUT HERE / AND HERE /}
endsnippet

which would output

Word w

Solution

  • One way to do it:

    snippet w
    $1 ${1/(.).*/\l$1/}
    endsnippet
    

    Please note that the replacement strings use Python regexps and syntax, not VimL.

    Another way (cleaner, IMO):

    snippet w
    $1 `!p snip.rv=t[1][0:1].lower()`
    endsnippet