Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop VS Code forcing me to use braces, otherwise the cursor position goes crazy (PHP, or apply it globally)

VS Code

if (1 == 1)  // When I hit enter here, the cursor moves to the next line at pos (0)
|
else  
    return; // When I hit enter here, cursor moves to next line/ pos 4
    |       // why is the cursor here? why not pos 0? 

Visual Studio (this is what I want to happen)

if (1 == 1)   // When I hit enter here, the cursor moves to the next line at
    |         // pos 1 if I'm working with Tabs or pos 4 for spaces)

This is not a problem in VS Code if you use braces like this:

if (1 == 1){
    return;
}

However, I don't like to use braces in those scenarios, and if I don't, VS Code naturally makes me end up writing this code which is also bad

if (1 == 1)
return;

I'm trying to get the same behaviour in VS Code. I can't seen to find a setting for this, or an extension. Please help. If I have to make an extension, or update the VS Code source and build it myself, I'm up for that, just please point me to the right direction. This is annoying.

like image 966
Gam Avatar asked May 18 '17 22:05

Gam


1 Answers

You can create code snippet. F1 "usn" => choose language >>

"if": {
    "prefix": "if",
    "body": [
        "if ($1)",
        "\t$2",
        "$3"
    ]
},
"ifelse": {
    "prefix": "ifelse",
    "body": [
        "if ($1)",
        "\t$2",
        "else",
        "\t$3",
        "$4"
    ]
},

Just in case add this to settings.json ctrl+,:

"editor.snippetSuggestions": "top",

like image 69
Alex Avatar answered Oct 17 '22 00:10

Alex