Use Ctrl-K Ctrl-C to comment selection and Ctrl-K Ctrl-U to uncomment selection

This tip will work for both Visual Studio .NET 2003 and Visual Studio 2005.

I use this feature all the time. These commands will comment / uncomment the current line if there is no selection.

Based on the feedback and comments, it seems that people like tips about keyboard shortcuts, so I’ll keep the keyboard shortcut tips coming.

Happy Editing!

Comments (11)

  1. Absolutely love this feature.


  2. I prefer single key shortcuts for things I do all the time, like this. So, I’ve customized the "Comment" and "Uncomment" buttons in my toolbar. Give them a title of "&Comment" and "&Uncomment", and make sure to specify "Show Image And Text" for each of these buttons.

    Once you’ve done that, you can use "Alt-C" to comment out a code chunk, and use "Alt-U" to uncomment a code chunk.

    The problem that you run into, though, is when you have a plugin like CodeSmart loaded, which will override the Alt-C to show CodeSmart’s menu.

  3. D. Philippe says:

    Derick: how is Alt + C a "single-key shortcut"? There’s not a whole lot of difference between Alt + C and Ctrl + K.

  4. I agree with derick. While having a shortcut to commenting and uncommenting is great, i don’t like the defaults at all.

    The first things I do when setting up a new VS instance is map commenting to F4 and uncommenting to shift-F4

  5. Luc Cluitmans says:

    I also don’t like multi-key shortcuts, for two reasons.

    First, they are hard to discover – if you aren’t searching for them you are unlikely to discover them.

    Second, well, the whole concept of double key shortcuts is a bit alien to the way shortcuts normally work in windows. They may be completely natural to Emacs users and others with a Unix background, but the average windows user (including programmers) is more used to ‘single’ shortcuts.

    I realize that in the case of VS there are simply far too many commands for the number of available shortcut keys, especially given the fact that shortcut keys in an ‘international’ program such as VS should work on all ‘normal’ keyboards. The latter is a stronger requirement than some people may realize. For instance, IIRC, the ‘standard’ shortcut for ‘jump to matching brace’ in VS2003 was Ctrl-/ . Sadly, my keyboard simply doesn’t have a ‘/’ key (‘/’ is shift-7 on my finnish/swedish keyboard). And in reverse, I have that same command now bound to Ctrl-Å, which would be pointless on a US keyboard, because it lacks a Å key. Basically, the only keys that can be assumed to be available are the 26 letter keys and the 10 digit keys; the location of symbol keys differs too much amongst different keyboard layouts in different countries to make standard shortcuts from them.

  6. Snorrk says:

    Why isn’t there a shortcut for Build Current Project? I use it all the time to syntax check and when I don’t want to recompile the whole solution because of a simple fix. I usually end up assigning ctrl+b, ctrl+b to it..

  7. joshunger says:

    Yea, yea I’m coming in a little late but I prefer Ctrl+Shift+C and Ctrl+Shift+R to match the shortcuts in Query Analyzer

  8. I’m not able to use the AOL Money&Finance site for stock quotes. I would like AOL to remove the advertisement crossing the section of the AOL Money&finance stock quote area so I am able to use that area for stock quotes.

  9. nick says:

    i didn’t have the build current project either so i went to tools -> options -> environment -> keyboard i think selected visual c# as the mapping scheme and the boom shift f6 builds the current project, i love the fact that these short cuts are extremely hard to find

  10. Robert Gale says:

    Double Ctrl-key sequences seem like a fine idea – wait a minute though, this is not a Microsoft idea, this was the way WordStar worked, where, for example, Ctrl-K introduced a load of blocK (note the K) commands.

  11. KITTY CAT says: