mattn / emmet-vim

emmet for vim: http://emmet.io/
http://mattn.github.io/emmet-vim
MIT License
6.41k stars 411 forks source link

Custom snippets fail to replace id or any other variable #414

Closed jeanCarloMachado closed 6 years ago

jeanCarloMachado commented 6 years ago

Here's my snippet config

{
    "php": {
       "extends": "html",
       "filters" : "html,c",
        "snippets": {
            "if": "if (${id}) {\n    ${child}\n}\n",
            "fun" : "function () {\n    ${child}\n}\n",
            "foreach": "foreach (\\$array as \\$key => \\$value) {\n ${child} \n}\n"
        }
    }
}

Using it like this:

<?php

fun>if#myVar>foreach

I get the following:

<?php

function () {
    if (${id}) {
        foreach ($array as $key => $value) {

        }

    }

}

The ${id} should be replaced by myVar right?

Using like this: fun>if[id=myVar]>foreach i get the same problem.

Best

ickerwx commented 6 years ago

I have a similar problem. Instead of using a separate file, I have defined snippets inside my .vimrc, but the effects are the same:

I have:

let g:user_emmet_settings = {                                                                               
\ 'html': {                                                                                                 
\   'snippets': {                                                                                           
\       "mdelem": "<!-- .element: class=\"${class}|\" -->",
\   }                                                                                                       
\ },                                                                                                        
\}

When I expand mdelem.foo I get:

<!-- .element: class="${class}" -->

I also tried using ${id} instead, but it also did not work.

mattn commented 6 years ago

Now added feature both should work.

jeanCarloMachado commented 6 years ago

I pulled the changes and it is not working for me. Maybe it works to html only? Should I do something special to make class and id identifiers work in other languages?

mattn commented 6 years ago

please put : before name like ${:id}.