Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UltiSnips doesn't automatically reload changes to snippets file

Tags:

vim

ultisnips

(Documenting this here because I couldn't find a good answer online.)

When using UltiSnips, the documentation says (2:12 in this screencast) that writing the .snippets file is enough to cause an automatic reload of the snippet. However, this doesn't work for me. What's happening?

like image 201
A.Wan Avatar asked Jun 21 '18 22:06

A.Wan


2 Answers

I had this question myself, as frequently updating my own .snippets files and not having them immediately available is unpleasant. After some experiments I discovered the answer:

:call UltiSnips#RefreshSnippets()

In case you are curious, I found it by typing :call <C-d> (a very long list, by the way).

However, this command does not update the autocompletion list of YouCompleteMe (which is mostly irrelevant, but sometimes you might want to browse through your options with description next to it).

like image 168
kctong529 Avatar answered Nov 04 '22 09:11

kctong529


Looks like the UltiSnips reload applies within a vim instance. So make sure to open & save the snippets file within the vim instance that you want the changes to take effect in.

To help with this, the command :UltiSnipsEdit will open the .snippets file corresponding to your correct file. You can configure how the snippets file opens using this command:

g:UltiSnipsEditSplit    Defines how the edit window is opened. Possible
                        values:
                        |normal|         Default. Opens in the current window.
                        |tabdo|          Opens the window in a new tab.
                        |horizontal|     Splits the window horizontally.
                        |vertical|       Splits the window vertically.
                        |context|        Splits the window vertically or
                                         horizontally depending on context.

Sample usage in .vimrc: let g:UltiSnipsEditSplit="context"

Note that this doesn't work as well if you'd like to make the changes in a different snippets file (e.g. you're working on a cpp file and you want to add a snippet for all c files (and your cpp.snippets file does extends c). If you're in this situation and you're editing your snippets frequently, consider keeping that snippets file open in a tab/pane.

Other suggestions / input welcome!

(from Documentation)

like image 36
A.Wan Avatar answered Nov 04 '22 08:11

A.Wan