Snippets vs. Abbreviations in Vim

后端 未结 4 1833
再見小時候
再見小時候 2021-02-15 12:40

What advantages and/or disadvantages are there to using a \"snippets\" plugin, e.g. snipmate, ultisnips, for VIM as opposed to simply using the builtin \"abbreviations\"

4条回答
  •  花落未央
    2021-02-15 13:08

    Everything that can be done with snippets can be done with abbreviations and vice-versa. You can have (mirrored or not) placeholders with abbreviations, you can have context-sensitive snippets.

    There are two important differences:

    • Abbreviations are triggered when the abbreviation text has been typed, and a non word character (or esc) is hit. Snippets are triggered on demand, and shortcuts are possible (no need to type while + tab. w + tab may be enough).
    • It's much more easier to define new snippets (or to maintain old ones) than to define abbreviations. With abbreviations, a lot of boiler plate code is required when we want to do neat things.

    There are a few other differences. For instance, abbreviations are always triggered everywhere. And seeing for expanded into for(placeholder) {\n} within a comment or a string context is certainly not what the end-user expects. With snippets, this is not a problem any more: we can expect the end-user to know what's he's doing when he asks to expand a snippet. Still, we can propose context-aware snippets that expand throw into @throw {domain::exception} {explanation} within a comment, or into throw domain::exception({message}); elsewhere.

提交回复
热议问题