How to comment out multiple lines by a hotkey?

Hi,

I saw in a video that someone is commenting out multiple lines by using a hotkey.

I think it’s Cmd+Shift+? on mac, but Ctrl+Shift+? doesn’t work on Windows for me.

Do you know what hotkey does that on Windows?

Also, do you know any other useful hotkeys that save you a lot of unnecessary typing and editing?

Thanks.

1 Like

Ctrl K + C will comment your current selection. Ctrl K + U will uncomment it. (Assuming you’re using VS)

The hotkeys are all listed next to their respective menu entries

4 Likes

Which IDE?
In Visual Studio it’s Ctrl + K + C and Ctrl + K + U.

The hotkeys in Visual Studio are customizable, so it’s usually better to look them up yourself.
Tools / Options / Environment / Keyboard

Some of the other ones I like, in no particular order:

  • Quick actions and refactoring suggestions (Most useful when your cursor is on top of red squiggles) (Default in VS 2015 and up: Ctrl + .)
  • Grep style file search (Default in VS 2015 and up: Ctrl + ,)
  • Intellisense (Default: Ctrl + Space Bar)
  • Available overloads (Only available when your cursor is inside the brackets of a method call) (Default: Ctrl + Shift + Space Bar)
  • Jump to definition (Default: F12)
  • Find all symbol references (Default: Ctrl K, R)
  • Rename symbol (Default: F2)
  • Jump to next error (Default: F8)
  • Format document with default VS style (very useful with xml docs or people as OCD about spaces as I am) (Default: Ctrl + K, D)
  • Toggle Breakpoint (Default: F9)
  • Remove all Breakpoints (Default: Ctrl + Shift + F9)
  • Start debugging (Default: F5)
  • Stop debugging (Default: Shift + F5)
  • Step in / Step over / Step up / Continue (Defaults: F11 / F10 / Shift + F11 / F5)
  • TestExplorer.Run/DebugAllTests (Defaults: Ctrl + R, A / Ctrl + R, Ctrl + A)
  • Run/Debug failing tests (No Default)
  • Run/Debug selected tests (No Default)
  • Jump to Solution Explorer (No Default)
  • Jump to Code (Default: F7)
  • Jump to Package Manager Console (Good for running any Powershell scripts) (No Default)

And here’s some other keyboard tricks:

  • Hold Ctrl while navigating your cursor with the left and right arrow keys to move word by word instead of character by character. This also works when selecting text with the Shift key
  • Hold Ctrl while navigating your cursor with the up and down arrow keys to scroll without losing your cursor’s place
  • Ctrl + Home is top of document, Ctrl + End is bottom
  • When Copy/Pasting code (looks over shoulder nervously … you didn’t hear it from me), select from the last character you want to copy UPWARDS to just after the last non-whitespace character you don’t want to copy. This usally means you are selecting some blank lines you wouldn’t normally select. Now you are in place to Ctrl + C, Ctrl + V, Ctrl + V. Yes, two Ctrl + V’s since the first will replace your current selection. It saves about 0.1 ms of repositioning your cursor :slight_smile:
1 Like

In addition to that there’re also the Pos1 (is it the Home key on english layouts?) and End keys

  • Pos1: jump to the beginning of a line (if you hit it again, it jumps to the first character in that line)
  • Ctrl + Pos1: jumps to the beginning of the file
  • End: jump to the end of the line
  • Ctrl + End: jump to the end of the file

All these can additionally combined with Shift for selection/deselection.

Also, an extensive list for VS shortcuts can be found here.

You can also hold down alt and press the up or down arrow to move lines around. Sometimes easier than copy and pasting. Works for multiple lines :slight_smile:

2 Likes

I didn’t know about it. :hushed:
Thanks :slight_smile:

In Visual Studio Code, it’s Ctrl-/

Bottom line: It depends on your IDE and IDE settings.

1 Like

On Monodevelop under OSX it is propeller-Slash to nop out a whole block of lines. Handy.