Alexander
Alexander

Reputation: 143

PHP block shortcut in Visual Studio Code

How can I open a basic PHP block in Visual Studio Code, like so - <?php ?>?

In Sublime Text I simply type php and press Tab, and the block is created. But I can't find the same shortcut for Visual Studio Code.

Upvotes: 7

Views: 17817

Answers (3)

AlNisr
AlNisr

Reputation: 151

Use:

  1. Open Visual Studio Code

  2. Open menu FilePreferencesUser Snippets

  3. Search and select "html.json"

  4. Now paste this code in {}:

     "php": {
         "prefix": ["<?", "<? ", "php"],
         "body": [ "<?php $1 ?>" ],
         "description": "php tag"
     }
    

Now you can use "<?" or "<? " or "php".

Upvotes: 15

Reichlich
Reichlich

Reputation: 354

I have used this in order to quickly order the space.

    "php": {
    "prefix": ["<?", "php"],
    "body": [
        "<?php",
        "",
        "$0",
        "",
        "?>"
    ],
    "description": "php tag"
}

You get something like this:

        <?php
        
        (code here)
        
        ?>

Upvotes: 1

benedikt
benedikt

Reputation: 1989

You can add a custom user snippet to Visual Studio Code:

  • Open "Preferences"
  • User Snippets
  • Select html.json (HTML)
  • Paste the following custom snippet:

    "php": {
        "prefix": "php",
        "body": [ "<?php $1 ?>" ],
        "description": "php tag"
    }
    

Upvotes: 35

Related Questions