Sublime Forum

Feature Request: "Edit Snippet…"

#1

As a user of Snippets, I want to be able to edit an existing snippet from within the app.

Currently I have to look up, or recall, where in the OS file system my custom snippets are stored. Then navigate the file system in order select a snippet file and open it in the app.

Instead, I want multiple ways within the app UI to locate, open, and edit Snippet files.

Idea 1
Add a “Snippet: Edit…” command to the Command Palette that opens an OS file browser at the location of the snippets folder/directory, so that a user can select an existing snippet to edit.

Idea 2
Currently, within the “Tools” > “Developer” sub-menu, there is a “New Snippet…” menu item. Add an “Edit Snippet…” menu item that opens an OS file browser at the location of the snippets folder/directory, so that a user can select an existing snippet to edit.

0 Likes

#2

As snippets are loaded only when located under Packages/, you can simply call View Package File from Command Palette and use fuzzy search to locate the snippet you want to edit.

0 Likes

#3

Interesting. Entering “View Package File” and then “snippet” does filter to a list of “.sublime-snippet” files. However it is across every package including all the Default languages. A user would then need to scroll until they found the snippets they created.

Filtering by “user snippet” shortens the list to the user created snippets (and any other package file that happens to include the letters “u s e r s n i p p e t” in any order.) This method is certainly an option, though not particularly memorable.

When the “Tools” > “Snippets” menu item, the “Tools” > “Developer” > “New Snippet…” menu item, and the “Snippet:” command are all first-class GUI features… why does editing a snippet need to be buried or rely on searching the file system? Both ideas 1 & 2 are extending existing GUI affordances for Snippets in a way that aligns with, and reinforces, where users already go to take action on Snippets and would reasonably expect to find an Edit Snippet feature.

0 Likes

#4

This is where a plugin comes in easily

import sublime
import sublime_plugin
import os

class EditUserSnippetCommand(sublime_plugin.WindowCommand):
    def run(self):
        user_dir = os.path.join(sublime.packages_path(), "User")
        self.snippet_files = [
            f for f in os.listdir(user_dir)
            if f.endswith(".sublime-snippet") and os.path.isfile(os.path.join(user_dir, f))
        ]

        if not self.snippet_files:
            sublime.message_dialog("No user snippets found in the User folder.")
            return

        self.window.show_quick_panel(
            self.snippet_files,
            self.on_done
        )

    def on_done(self, index):
        if index == -1:
            return  # Cancelled
        snippet_path = os.path.join(sublime.packages_path(), "User", self.snippet_files[index])
        self.window.open_file(snippet_path)
0 Likes

#5

Then just add to your command palette as a Edit User Snippets

This was written on a phone. Untested

0 Likes

#6

Well, I just was providing a possible way using existing functions, nothing more nothing less.

That being said, editing existing snippets doesn’t need to be limited to user defined ones. It is easily possible someone wants to tweak a snippet from a bundled default syntax package.

No-one wants to burry anything. This functionality just hasn’t been requested yet. I don’t even find a plug-in adding such function. Not even PackageDev has it.

0 Likes