Skip to content
Advertisement

Visual Studio Code native formatter messing with PHP code format

I’m having problems with Visual Studio Code. When I’m editing PHP code, and inputing an if/else statement, when I type else and hit ENTER, I get this crap formatting that looks like the following code segment and I have to manually change it (which is annoying to say the least).

if (...)
{
}
else {
    # code...
}

I turned off all extensions and it’s still doing it, so it’s something native in Visual Studio Code itself. I’ve scoured the settings and it doesn’t seem to be anything in there. A google search didn’t help much either. I found a similar type of question here on Stack Overflow, but that was dealing with C++, and was the opposite of what I’m trying to do. It’s almost like it’s some type of autocomplete function, but I have that turned off too.

Any ideas where to look?

Thanks.

Advertisement

Answer

After some digging, I figured out what was going on. It’s a feature of Visual Studio Code that I was not aware of. The feature is code snippets. It doesn’t appear anywhere on the menus which is why I missed it. So you have to go (View -> Command Palette) then type in insert snippet. Then you can select all the different snippets that are available. You can also turn them off, which is what I did. The specific one was ‘else’. Once that was done, it didn’t do it anymore.

So, problem solved.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement