How to create short snippets in Vim?

前端 未结 6 1886
无人共我
无人共我 2020-12-08 14:11

I have recently started using Vim as my text editor and am currently working on my own customizations.

I suppose keyboard mappings can do pretty much anything, but f

6条回答
  •  粉色の甜心
    2020-12-08 15:15

    As another suggestion (although slightly different) using vim's built in functionality:

    :iabbrev def def(): #
    

    Now whenever you type def followed by a space or other non-word character, it will expand to the same as what you've given as the output of SnippetsEmu (the space comes from the space you entered to trigger the completion).

    This approach doesn't suffer the "lag" issue you encountered using :inoremap, and is built-into vim. For more information on this feature, look at :help abbrev.

    You may be concerned that being triggered by space not tab it will trigger unnecessarily, but in general vim is pretty smart about when to trigger it. The issue can be additionally mitigated by enabling the abbreviation only for certain file-types (eg, python):

    au filetype python :iabbrev ... etc
    

    Snip[ets] (Manager|Emu|Mate|.vim) is of course also a perfect solution, but it's nice to be aware of the alternatives (especially when they are built in).

提交回复
热议问题