overwriting snippets

Bug #1236866 reported by fehlerfix on 2013-10-08
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
UltiSnips
Fix Committed
Undecided
Unassigned

Bug Description

I'm trying to overwrite bundled snippets using the "!" option. This does not work as descriped in the documentation in most cases. Adding a new modified snippet with the same trigger and "!" option only leads on triggering to the list where both versions are listed.
The only exception I found so far is the following:
I can overwrite the bundled snippets defined in texmath.snippets.
For example:

snippet eq "Equation" !b
\begin{equation}
    \label{eq:$1}
    $2
\end{equation}
$0
endsnippet

in my local tex.snippets overwrites the bundled version from texmath.snippets

snippet eq "Equation" b
\begin{equation}
        $0
\end{equation}
endsnippet

Since I find most bundled useful I don't want to disable them all.

:py import sys; print sys.version
2.7.2 (default, Aug 19 2011, 20:41:43) [GCC]

SirVer (sirver) wrote :

UltiSnips searches in 'runtimepath' for snippet directories but traverses
'runtimepath' in reverse order (last item first). If you would like to have
UltiSnips traverse 'runtimepath' in the standard order, add this to your vimrc
file: >
   let g:UltiSnipsDontReverseSearchPath="1"

have you tried that? It depends if you use vundle, pathogen or something else what will work for you.

Changed in ultisnips:
status: New → Incomplete
fehlerfix (bugeye) wrote :

Thank you. Your suggestion helps indeed. Now, that I think of it, it seems quite reasonable. I'm using vundle. Maybe a hint in the documentation where the "!" option is explained would help someone else, too. Just reading "Use this option to overwrite bundled snippets with user defined ones." might be misleading.

SirVer (sirver) wrote :

A patch would be very welcome! Just add it to the docs where you woudl have expected it.

In the future I would love to autodetect this actually. It is easy too - if your .vimrc comes after UltiSnips in the rtp, you should traverse forward, otherwise traverse backward. A pacth for this would be even more welcome.

fehlerfix (bugeye) wrote :

Here is my suggestion:

   ! Overwrite - A snippet with this option will overwrite all previously
       defined snippets with an identical tab trigger. What previously means
       in this context depends on the order UltiSnips traverses the 'runtimepath'.
       (Compare g:UltiSnipsDontReverseSearchPath). This might depend
       on your installation type (Pathogen, Bzr, Vundle). The default behavior
       is to display list of snippets matching the tab trigger and let the
       user pick the one they want. Use this option to overwrite bundled
       snippets with user defined ones.

or as diff

591,594c591
< defined snippets with an identical tab trigger. What previously means
< in this context depends on the order UltiSnips traverses the 'runtimepath'.
< (Compare g:UltiSnipsDontReverseSearchPath). This might depend
< on your installation type (Pathogen, Bzr, Vundle). The default behavior
---
> defined snippets with an identical tab trigger. The default behavior

I agree that an autodetect would be very nice. But I'm afraid that at the moment I will not find the time to look at this. Even though this nice plugin really helps to save time... so thanks for your work.

SirVer (sirver) wrote :

Nice and clean. I committed this. Thanks for your contribution.

Changed in ultisnips:
status: Incomplete → Fix Committed
Aaron Bieber (aaron-g) wrote :

Apologies for bumping an old issue, but it is related to this thread and may not be a bug in and of itself.

I have two systems, one OS X and another Ubuntu, both running identical Vim configurations with identical "runtimepath" values, but my own snippets (stored in ~/.vim/snippets/) only override the default snippets on one machine. The behavior of g:UltiSnipsDontReverseSearchPath is apparently reversed on these two machines.

That is to say, with g:UltiSnipsDontReverseSearchPath set to "1", my snippets work properly on the Ubuntu machine, but not in OS X. If I set that option to "0" my snippets then work in OS X but not in Ubuntu.

I wanted to try my hand at auto-detecting the correct traversal direction, but the values of &runtimepath in both Vims are identical. I tested this by opening a new buffer and typing `i<C-R>=&runtimepath<CR><Esc>:%s/,/\n/g` to output the value of &runtimepath and split it into lines by the commas. Side-by-side they're exactly the same.

Stumped!

SirVer (sirver) wrote :

Try unsetting the variable and pull. Make sure you use the newest version on all systems (maybe that is already the issue?) Same Vim version too? The travesal is now auto detected. Maybe that helps already.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers