Mar 10, 2014

How to add a new snippet for Zed?

Following this introduction to Zed, I encountered a problem to create a snippet. It's actually an open issue.
So I wanted to share it here.

I also wanted to share a few things I added to my user.json file. It's also a good idea to back it up as you could use it in any chrome browser you could find.
    "preferences": {
        "theme": "monokai",
        "scrollSpeed": 4,
        "gotoExclude": ["/tags", "*.png", "*.gif", "*.jpg", "*.mp4"]
    }
In the exclude part,  I added a few extensions that I encounter while working on web projects. It saves some time when you look for a file with the Ctrl-E command.
I also added the ctp extension (from CakePHP) to be managed with the PHP mode.

Here is an example if you want to use Zed snippets system with PHP :
    "modes": {      
        "php": {
            "name": "PHP",
            "highlighter": "ace/mode/php",
            "extensions": ["php", "php4", "ctp"],
            "commands": {
                "Tools:Complete:Snippet": {
                    "scriptUrl": "/default/command/snippet_completer.js",
                    "snippets": {
                        "class": "class=\"${1}\"",
                        "foreach": "foreach (${1} as ${2}) {\n\t${3}\n}",
                        "if": "if (${1}) {\n\t${2}\n}",
                        "php": "<?php ${1} ?>"
                    }
                }
            },
            "handlers": {
                "complete": ["Tools:Complete:Builtin","Tools:Complete:Snippet"]
            }
        }
    }
If you want to add your own, just duplicate the lines under snippets.

No comments:

Post a Comment