6

I'm struggling a bit with yasnippet. My question must be very basic but I would like to modify some snippets but I can't locate them. I have for example a snippet style for html-mode but it does not appear where it should be that is either under :

~/.emacs.d/elpa/yasnippet

or

~/.emacs.d/snippets

My config is the following:

(add-to-list 'load-path
         "~/.emacs.d/elpa/yasnippet-20160801.1142")
(require 'yasnippet)
(yas-global-mode 1)
(add-to-list 'yas-snippet-dirs "~/.emacs.d/snippets")

Any would be appreciated!

0

4 Answers 4

6

Considering your configuration, using elpa, they are located in ~/.emacs.d/elpa/yasnippet-20160801.1142/snippets.

Your custom snippets should be at ~/.emacs.d/snippets so they don't get overwritten in each update. Also check the value of the variable yas-snippets-dirs with Ctr-h v yas-snippets-dir.

4

In your buffer, M-x yas-visit-snippet-file, then type the name of the snippet you want to edit, or choose from a prompted list. Then it will open a buffer for you to edit. From the buffer you can M-: buffer-file-name to see the path of the file containing the snippet.

2

If you want to edit a snippet from the mode you are in just press the standard commands :

C-c & C-v to view an existing snippet (you should know what name it has)

or

C-c & C-n to create a new snippet for the mode you're in.

In this way you don't have to care about where the snippets are located, YASnippet should do that automatically.

You can also open existing/new snippets by clicking on the menu bar YASnippet (if you're using the GUI).

I hope this could help you.

0

Try (setq yas-snippet-dirs '("~/.emacs.d/snippets"))

When you miss a snippet, that you've already created, use yas-reload-all.

And you don't need the first line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.