UltiSnips doesn't automatically reload changes to snippets file
Asked Answered
S

3

18

(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?

Stile answered 21/6, 2018 at 22:56 Comment(0)
P
36

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).

Prinz answered 16/10, 2018 at 18:5 Comment(3)
If you run :YcmRestartServer after refreshing the snippets, YouCompleteMe will show the completion.Pulsometer
If you are using CoC and you can use :CocRestart after refreshing snippetsLunseth
Thanks to this answer, I added the following line to my ~/.vimrc ... nmap <leader>w :w<cr> | :call UltiSnips#RefreshSnippets() ... I use my spacebar as <leader>, and thus "space-w" writes my file (buffer). I appended the solution above, so that whenever I edit my snippets file, I simply press "space-w" to save the edits and simultaneously reload the edited snippet(s) file.Stcyr
S
3

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)

Stile answered 21/6, 2018 at 22:56 Comment(0)
A
0

I haven't been able to find a satisfactory answer to this either. Until somebody can post something better, I recommend just using

:e!

This reloads the current window to the most recently-saved file. I know it's not much, but it's what I'm using until I find a better way to do it.

Attract answered 24/6, 2018 at 15:30 Comment(1)
Warning: save before you do this, or you could lose your current edit.Furuncle

© 2022 - 2024 — McMap. All rights reserved.