I have the following snippet:

# -*- mode: snippet -*-
# contributor: Song Qiang <[email protected]>
# key: m
# group: Math
# name: Inline math \( ... \)
# --

and I want it to be available for both latex-mode and org-mode. How can this be achieved? I could symlink, but I'm trying to find a smarter way.


2 Answers 2


The Yasnippet documentation explains that you will need to include a .yas-parents file with the parent modes:

It's very useful to have certain modes share snippets between themselves. To do this, choose a mode subdirectory and place a .yas-parents containing a whitespace-separated list of other mode names. When you reload those modes become parents of the original mode.

|-- c-mode
|   |-- .yas-parents    # contains "cc-mode text-mode"
|   `-- printf
|-- cc-mode
|   |-- for
|   `-- while
|-- java-mode
|   |-- .yas-parents    # contains "cc-mode text-mode"
|   `-- println
`-- text-mode
    |-- email
    `-- time

Hence, you could, for example, put your snippet in a text-mode directory, and then, in the latex-mode and org-mode directories, include a .yas-parents file that include the text text-mode.

  • 3
    However, if I have well understood, you can only share entire modes, but not individual snippets across several modes? Commented Jan 16, 2018 at 12:02

A few more approaches for sharing snippets between modes:

  1. Let's say you want certain snippets to be shared in both modes: html-mode & css-mode:

    You need to create a separate folder and give it a unique name like html-css-mode where you put the snippets you want to reuse.

    Once that's done you need to require this virtual mode in html-mode & css-mode folders by creating a .yas-parents file with html-css-mode content matching your virtual mode name.

  2. If your snippet belongs to more that one mode or you're want to take a lazy approach - you can put your snippets into fundamental-mode folder which is available in all modes.

Your Answer

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

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