Search code examples
vimsnipmate

Is there a way to get a snippet to work immediately after a word?


Whenever I try to use a snippet (using snipMate) after a word, without a space, it does not work. So I have to hit space, type my snippet, hit tab, and then eliminate the space. Is there a better way of doing this? Is there a way to get the snipppets to work even immediately after a word? Here is what I mean:

let us say my snippet is this:

snippet test
        <some code>${1}</code>${2}

typical use:

hello test[TAB]

turns into this:

hello <some code>|</code>

but if I try this:

hellotest[TAB]

it turns into this:

hellotest_____

the _ being white space. Is there a way to fix this?


Solution

  • Vim abbreviations can be of three types (full-id, end-id, and non-id, cp. :help abbreviations), which help solve this problem. snipMate, however, allows all non-whitespace characters for snippet names, and therefore has to rely on whitespace for separation.

    You have to modify the parsing of the snippet name, in plugin/snipMate.vim, it's in the function TriggerSnippet():

    let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')