skip to Main Content

In my VScode, on mac, when using the commentLine shortcut "command+/", in an html.erb file, instead of commenting out the line with an html <!-- comment --> it wraps the highlighted code in a <% begin %> <% end %> block. How can I change the behaviour of VScode’s "editor.action.commentLine" function, which is what I believe this keyboard shortcut triggers, to insert the desired html comment tag?

2

Answers


  1. Chosen as BEST ANSWER

    A solution that I found was to within VSCode's 'language-configuration-erb.json' file (path–'/Users/your_username/.vscode/extensions/bung87.rails-0.17.8/language-configuration-erb.json') make this change:

    (mac–'command+shift+p', then type name to find the above file)

    {
        "comments": {
            "blockComment": [
                // "<%n=begin%>n",
                // "n<%n=end%>"
                "<!--",
                "-->"
            ]
        },
    ...
    }
    

  2. Select the text you want and press ctrl+/ or command+/

    You can define the following key binding:

      {
        "key": "ctrl+/",  // or command+/ for Mac
        "command": "editor.action.insertSnippet",
        "when": "editorHasSelection && editorLangId == erb",
        "args": {
            "snippet": "${TM_SELECTED_TEXT/^(.*)$/<!-- $1 -->/}"
        }
      }
    

    Maybe you have to change the languageID: erb

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search