skip to Main Content

In other IDE’s you can comment out a line of code with "CTRL+/" shortcut.

But that doesn’t seem to work in VS Studio 2022. Tried to do some googling, but there is only how it is done in multiple lines. What about one line commenting? Without outlining code, I just want to put cursor anywhere in a line, and be able to comment it out.

Is there any way to do that?

3

Answers


  1. Visual Studio uses different key binding then Visual Studio Code. To comment a selection use ctrl+k+c and to uncomment the selection use ctrl+k+u. You can find other key bindings under Edit->Advance as shown in the below screenshot.

    enter image description here

    Login or Signup to reply.
  2. There are multiple commenting commands in Visual Studio, and not all of them are implemented in each language so YMMV.

    The commands are:

    • Comment Selection (Ctrl+K, Ctrl+C): this always comments out the selected region (or caret line if there is no selection). If it is already commented, this may do nothing, or may add another level of commenting (depends on language implementation).
    • Uncomment Selection (Ctrk+K, Ctrl+U): this always uncomments the selected region (or caret line if there is no selection). If it is already uncommented, this should do nothing.
    • Toggle Block Comment (Ctrl+Shift+/): this toggles whether the current line is commented (if it is already commented, uncomment; if it is not commented, apply comment) using block comment syntax. If a language does not offer a block comment syntax (such as /* */), it may apply single-line comments to each line in the selection, or it may do nothing.
    • Toggle Line Comment (Ctrl+K, /): this toggles whether the selected lines are commented using single-line comment syntax (e.g. //). If the selected lines are in a mixed state of comments and non-comments, the behavior may set all of them to one state (e.g. apply // at the beginning of each line, including the ones that are already commented).

    All of these keyboard shortcuts are customizable in Tools -> Options -> Environment -> Keyboard. Look for the command names Edit.CommentSelection, Edit.UncommentSelection, Edit.ToggleBlockComment, and Edit.ToggleLineComment.

    Login or Signup to reply.
  3. So, it turns out Microsoft uses "Ctrl+K, Ctrl+C" statement synonymously to "Ctrl+K+C". It took me a while to figure that out.

    Finally, I just changed the entire keyboard shortcuts set to Visual Studio Code. For that go to Tools -> Options -> Keyboard. Change the Apply the following additional keyboard mapping scheme: to Visual Studio Code.


    Solution originally edited by user19693556 within the question

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search