How to add new snippets to snipMate in VIM

后端 未结 6 578
遥遥无期
遥遥无期 2021-02-08 07:03

Ive just started using the sniptMate plugin for VIM and love it, however, since my collection of snippets isn\'t huge, I\'d like to be able to add new snippets dynamically rathe

相关标签:
6条回答
  • 2021-02-08 07:20

    Just place your own snippets (given you want to use them in all files you edit) here:

    ~/.vim/after/snippets/_.snippets
    

    For example:

    snippet test
      {"foo": "${1}", "bar": "${2}"}
    
    0 讨论(0)
  • 2021-02-08 07:29

    If you are using pathogen, you can write your own snippets without polluting the original ones. To do this, add your snippets to ~/.vim/bundle/mysnippets/snippets/*.snippets. FYI, mysnippets can be any name.

    Moreover, it's a convention to add a _.snippets file in that directory where you add snippets which should be available everywhere irrespective of the filetype.

    0 讨论(0)
  • 2021-02-08 07:31

    Snippets for Snipmate are usually stored in the ".vim" directory in the snippets folder.

    You can pretty easily edit the snippet file for the language you are working on.

    0 讨论(0)
  • 2021-02-08 07:37

    If you use vundle to manage your plugins on Windows and you have installed

    vim-snipMate & vim-snippets
    

    If you want to add your customization, say to 'html' filetype, you just go to this folder:

    $HOME/vimfiles/bundle/vim-snippets/snippets/ 
    

    create a new file and name it in this format:

    html_bsmith.snippets  
    

    (it must be underscore after html, see :help snipmate)

    Then vim will load your file automatically.

    If you customization can be used anywhere, just put it in the existing file:

        _.snippets
    
    0 讨论(0)
  • 2021-02-08 07:38

    You can put your own snippets in ~/.vim/after/snippets/ or whatever the equivalent on Windows is... read :h snipMate for the filename syntax.

    0 讨论(0)
  • 2021-02-08 07:41

    I'm not sure it's meant to be done like this but you can try calling the MakeSnip function from within file you're currently working on. For example:

    :call MakeSnip(&ft, "foo", "<foo>${1}</foo>")
    

    &ft will pass the filetype of the file you're currently editing, "foo" is the trigger and "<foo>${1}</foo>" is the replacement text.

    Of course, snippets created like this won't persist. So why not have the snippets file open in another buffer, define new snippets there as necessary, then do:

    :call ReloadSnippets(&ft)
    

    and your new snippet will be available. You could even define an autocmd to call the ReloadSnippets function when you write the snippets file.

    0 讨论(0)
提交回复
热议问题