Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio + Razor: "Surround with..." Snippets

I'm trying to use these awesome VS "Surround With" snippets with VS, but they dont't work as expected. Say I have some code:

<p>Success!</p>

If I select this code and select the ASP.NET MVC 4 / ifcs4 snippet, I would expect that my code becomes this:

@if (true) {
    <p>Success!</p>
}

But instead, it becomes this:

<% if (true) { %>
    <p>Success!</p>
<% } %>

These <% tags aren't even used in the Razor syntax, so why are they there? Isn't there any way I could put it to work in the expected manner?

like image 247
Yan Paulo Avatar asked Jul 22 '15 20:07

Yan Paulo


People also ask

How do I create a multiline snippet in Vscode?

press ctrl + shift + P and type "Create snippet" on the command palette and press ENTER. snippet name, type snippet shortcut and then type snippet description. You are now good to go.

How do I enable snippet code in Visual Studio?

To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language (by language identifier) for which the snippets should appear, or the New Global Snippets file option if they should appear for all languages.

Where are Visual Studio code snippets stored?

Depending on your plaform, your user snippets file is located here: Windows %APPDATA%\Code\User\snippets\(language). json.

How do I use angular snippets?

Type part of a snippet, press enter , and the snippet unfolds. Alternatively, press Ctrl + Space (Windows, Linux) or Cmd + Space (macOS) to activate snippets from within the editor.


1 Answers

I think it's just an oversight on Microsoft's part.

I found the snippets path by choosing Tools -> Code Snippets Manager, selected HTML as language and selected ifcs4. The path for the snippet is (for VS 2013):

C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Visual Studio 2013\Snippets\HTML\1033\ASP.NET MVC 4\ifcs.snippet

I updated the file with Razor-style if and it worked just fine even without reloading the project.

like image 163
Volkan Paksoy Avatar answered Sep 25 '22 15:09

Volkan Paksoy