norcalli / snippets.nvim

GNU General Public License v3.0
277 stars 13 forks source link

How can I add a value of placeholder as argument to function? #15

Closed ghost closed 4 years ago

ghost commented 4 years ago

I have this function to capitalize the first letter of a word:

function titleCase(first, rest)
   return first:upper()..rest:lower()
end

And want to use this in my snippet: Basically i want capitalize what I typed on first placeholder

  typescriptreact = {
    ["ush"] = [[
    const [${1}, ${=string.gsub($1, "(%a)([%w_']*)", titleCase)}] = useState(${3})
    ]]
  };

I'm very noob on lua so apologies if it's a dumb question, but I'm really struggle with this

ghost commented 4 years ago

Already solved! It was just lack of reading the documentation haha.

Solution:

    ["ush"] = [[
const [${1}, ${1|string.format('set%s', S.v:sub(1, 1):upper()..S.v:sub(2))}] = useState(${3})$0
    ]],