The ultisnips-mode is an Emacs major mode for editing Ultisnips snippet files (*.snippets files). This mode provides syntax highlighting to facilitate editing Ultisnips snippets.
(Vim’s UltiSnips is a snippet solution for Vim, and its snippets can be used in Emacs by converting them to the Yasnippet format using Ultyas.)
Features
- Syntax highlighting for UltiSnips:
snippet,endsnippet,global,endglobal,priority, comments, and placeholders in the form of${1:value}or$1… - Integration with
outline-minor-modeorhs-minor-modeto enable folding ofsnippet->endsnippetandglobal->endglobalblocks. - Support for commenting and uncommenting UltiSnips snippets using standard Emacs commands, such as
comment-or-uncomment-region. - Add
*.snippetstoauto-mode-alistto automatically enableultisnips-mode.
Installation
To install ultisnips-mode from MELPA:
-
If you haven’t already done so, add MELPA repository to your Emacs configuration.
-
Add the following code to your Emacs init file to install ultisnips-mode from MELPA:
(use-package ultisnips-mode
:commands ultisnips-mode
:mode ("\\.snippets\\'" . ultisnips-mode))
Frequently Asked Questions
Folding snippet blocks with hs-minor-mode
Activating hs-minor-mode provides the ability to collapse and expand snippet -> endsnippet blocks, making navigation in large snippet files much easier.
To enable hs-minor-mode automatically for Ultisnips files, add the following to the Emacs configuration:
(add-hook 'ultisnips-mode-hook #'hs-minor-mode)
NOTE: As an alternative to hs-minor-mode, ultisnips-mode also supports outline-minor-mode; however, hs-minor-mode is recommended because it can reliably fold entire blocks from snippet to endsnippet. In contrast, outline-minor-mode uses only the snippet line as a header and may hide everything between the first snippet and the next one, including comments.
For a better and more intuitive way to fold and unfold snippets, it is recommended to use the kirigami.el emacs package.
Hiding all snippets with hs-minor-mode when opening *.snippets files
The following configuration automatically folds all code blocks when ultisnips-mode is enabled, collapsing all snippets:
(defun my-ultisnips-mode-fold-all ()
"Fold all snippet blocks using `hs-minor-mode'."
(hs-minor-mode 1)
(hs-hide-all))
(add-hook 'ultisnips-mode-hook #'my-ultisnips-mode-fold-all)
This ensures a cleaner view of snippets, collapsing all regions by default and allowing selective expansion as needed.
Is there a package that allows using UltiSnips directly in Emacs, or is it necessary to first convert them to the Yasnippet format?
Yes, conversion to Yasnippet is required.
A command-line tool called Ultyas facilitates the conversion of snippets from UltiSnips to Yasnippet format.
How does the author use ultisnips-mode and Ultyas?
The author maintains all snippets in their original UltiSnips format for Vim and developed a shell script that automatically scans the UltiSnips directory, generating the corresponding Yasnippet files using Ultyas.
He uses the ultisnips-mode Emacs package to edit snippets, which provides syntax highlighting and code folding via hs-minor-mode.
This workflow allows editing and storing a single set of snippets while making them available in Vim and Emacs.
Author and License
The ultisnips-mode Emacs package has been written by James Cherti and is distributed under terms of the GNU General Public License version 3, or, at your choice, any later version.
Copyright (C) 2025-2026 James Cherti
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.
Links
- ultisnips-mode.el @GitHub
- Ultyas: A command-line tool designed to simplify the process of converting code snippets from UltiSnips to YASnippet format.
Other Emacs packages by the same author:
- minimal-emacs.d: This repository hosts a minimal Emacs configuration designed to serve as a foundation for your vanilla Emacs setup and provide a solid base for an enhanced Emacs experience.
- compile-angel.el: Speed up Emacs! This package guarantees that all .el files are both byte-compiled and native-compiled, which significantly speeds up Emacs.
- easysession.el: Easysession is lightweight Emacs session manager that can persist and restore file editing buffers, indirect buffers/clones, Dired buffers, the tab-bar, and the Emacs frames (with or without the Emacs frames size, width, and height).
- vim-tab-bar.el: Make the Emacs tab-bar Look Like Vim’s Tab Bar.
- elispcomp: A command line tool that allows compiling Elisp code directly from the terminal or from a shell script. It facilitates the generation of optimized .elc (byte-compiled) and .eln (native-compiled) files.
- tomorrow-night-deepblue-theme.el: The Tomorrow Night Deepblue Emacs theme is a beautiful deep blue variant of the Tomorrow Night theme, which is renowned for its elegant color palette that is pleasing to the eyes. It features a deep blue background color that creates a calming atmosphere. The theme is also a great choice for those who miss the blue themes that were trendy a few years ago.
- dir-config.el: Automatically find and evaluate .dir-config.el Elisp files to configure directory-specific settings.
- flymake-bashate.el: A package that provides a Flymake backend for the bashate Bash script style checker.
- flymake-ansible-lint.el: An Emacs package that offers a Flymake backend for ansible-lint.
- inhibit-mouse.el: A package that disables mouse input in Emacs, offering a simpler and faster alternative to the disable-mouse package.
- quick-sdcv.el: This package enables Emacs to function as an offline dictionary by using the sdcv command-line tool directly within Emacs.
- enhanced-evil-paredit.el: An Emacs package that prevents parenthesis imbalance when using evil-mode with paredit. It intercepts evil-mode commands such as delete, change, and paste, blocking their execution if they would break the parenthetical structure.
- stripspace.el: Ensure Emacs Automatically removes trailing whitespace before saving a buffer, with an option to preserve the cursor column.
- persist-text-scale.el: Ensure that all adjustments made with text-scale-increase and text-scale-decrease are persisted and restored across sessions.
- pathaction.el: Execute the pathaction command-line tool from Emacs. The pathaction command-line tool enables the execution of specific commands on targeted files or directories. Its key advantage lies in its flexibility, allowing users to handle various types of files simply by passing the file or directory as an argument to the pathaction tool. The tool uses a .pathaction.yaml rule-set file to determine which command to execute. Additionally, Jinja2 templating can be employed in the rule-set file to further customize the commands.
- kirigami.el: The kirigami Emacs package offers a unified interface for opening and closing folds across a diverse set of major and minor modes in Emacs, including
outline-mode,outline-minor-mode,outline-indent-minor-mode,org-mode,markdown-mode,vdiff-mode,vdiff-3way-mode,hs-minor-mode,hide-ifdef-mode,origami-mode,yafolding-mode,folding-mode, andtreesit-fold-mode. With Kirigami, folding key bindings only need to be configured once. After that, the same keys work consistently across all supported major and minor modes, providing a unified and predictable folding experience. - buffer-guardian.el: Automatically saves Emacs buffers without requiring manual intervention. By default, it triggers a save when the user switches to another buffer, switches to another window or frame, Emacs loses focus, or the minibuffer is opened. Beyond standard file buffers, buffer-guardian also manages specialized editing buffers such as org-src and edit-indirect. Additional features, disabled by default, include periodic or idle-time saving of all buffers, automatic exclusion of remote, nonexistent, or large files, and support for custom exclusion rules via regular expressions or predicate functions.