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
Visual Studio uses different key binding then Visual Studio Code. To comment a selection use
ctrl+k+c
and to uncomment the selection usectrl+k+u
. You can find other key bindings underEdit
->Advance
as shown in the below screenshot.There are multiple commenting commands in Visual Studio, and not all of them are implemented in each language so YMMV.
The commands are:
/* */
), it may apply single-line comments to each line in the selection, or it may do nothing.//
). 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
, andEdit.ToggleLineComment
.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: toVisual Studio Code
.Solution originally edited by
user19693556
within the question