Alex Dubrovsky
Alex Dubrovsky

Reputation: 260

C-style comments in VS Code

Is it possible to configure VS Code to use C-style comments (/**/) instead of C++ style ones (//) for C code only? My Gooogle-fu might be weak, but I haven't found any useful solution to it so far.

Upvotes: 3

Views: 5516

Answers (4)

Alexander Chashka
Alexander Chashka

Reputation: 31

You can actually redefine it entirely to your liking, but it will require some fiddling with the package.json of the C/C++ extension. This file will probably be located (at least on my Ubuntu it is) in ~/.vscode/extensions/ms-vscode.cpptools-YOUR_VERSION_NUMBER. So open it

code ~/.vscode/extensions/ms-vscode.cpptools-YOUR_VERSION_NUMBER/package.json 

in terminal. In this file you need to locate an object named "contributes". Within this object you'll need to create an array called "languages" and add a language object:

"languages": [
    {
        "id": "c",
        "extensions": [
            ".c", ".h"
        ],
        "configuration": "./my-c-configuration.json"
    }
]

now the path in the configuration property needs to point to another .json file in which you will add the new definition for the comment command: (in the "my-c-configuration.json" file, created in the same directory)

{
  "comments": {
    "lineComment": [ "/*", "*/" ],
    "blockComment": [ "/*", "*/" ]
  }
}

Save both files, reopen the VSCode, and that's all.

Upvotes: 3

inhaler
inhaler

Reputation: 185

VS-Code Keyboard Shortcuts

It's July, 2020 and latest vs code stable version is Version 1.47.

Toggle block comment shortcut is : Shift+Alt+A.

Official Source : VS-Code Keyboard Shortcuts

Upvotes: 2

cakel
cakel

Reputation: 63

Was this changed ?
To me, it works with Ctrl+Alt+A.

Upvotes: 1

mandyedi
mandyedi

Reputation: 66

Select the line or lines then press Ctrl + Shift + A.

Upvotes: 2

Related Questions