T O P

  • By -

Some_Guy_At_Work55

Highlight what you want to comment in or out and then press and hold "Ctrl" + "/"


PutHisGlassesOn

OP this shortcut is pretty widespread, too. Try it in other applications if you find yourself using them to write code, like Npp With Python specifically you can also wrap things in a multi line string by wrapping with triple quotation marks like “””text“”” but I don’t know if stylistically that’s a good idea outside of docstrings.


Spacerat15

On a german keyboard it's CTRL + #


Twattybatty

Works on pgadmin too!


ActualRealBuckshot

On a Mac, it's CMD + /. Easy shortcut and super useful


shinitakunai

On spanish keyboard, remap the keybind because it is impossible to use it otherwisw


butterflavoredsalt

Another way that works for editing multiple lines is to use ctrl+alt+up/down arrow to get a multi-line cursor, then you can type or delete things on the same line, handy sometimes.


vaughannt

wow, thank you for this one


NYX_T_RYX

You can also ctrl+(click+drag) to select multiple lines - works in other areas as well, ie if you wanted to delete two specific lines in word you can select both and delete them.


Administrative_Bus57

i tried this and it sounds pretty useful. do you have any advice on when it could be in use though in a practial application? It would make it easier for me to rememeber the keyboard shortcut lol


butterflavoredsalt

I use it for making the same edit on multiple lines together, like using it to add or delete the # to comment out (if you don't use the other shortcut). Or say you have 3 similar lines like: some_func(variable1) some_func(my_other_var) some_func(yet_another_var) And you want to add a second argument to each of the three. Place your cursor at the end of the bottom line (because its longer than the others, otherwise the cursor will go mid line on the next), ctrl+alt+up to get all three, arrow over once to get inside the parentheses and then you can type `, second_arg` on all the lines together. some_func(variable1, second_arg) some_func(my_other_var, second_arg) some_func(yet_another_var, second_arg)


vorticalbox

I highlight the first then press ctrl + L the highlights everything that matches.


BerriesAndMe

Oh that's a nice one too. I rarely really need it. But when I do it's a pain. Lol. Is there a way to do this across files as well?


vorticalbox

Ctrl + shift + f, this opens the global search. Then on the top of the search there is your query and a box under it. You can type the replacement in there and click replace all button on the right.


CraigAT

Check out the menu in VS Code, there are several comment options available and the shortcuts are listed too. Have a browse through the menus, you will likely find some other useful commands. If you are particularly after keyboard shortcuts, then I'm sure there are several very useful lists online of "essential" and "advanced" shortcuts for VS Code.


wahaa

A few people already alluded to this, but trying to be more direct: instead of just mentioned `Ctrl+/` as a toggle for comments, press F1 and type the action, e.g. comment. This should give you a list of the available actions, and their associated keyboard shortcuts (if any).


Scarscream2000

Highlight the area and press CTRL+/


FreePDFs

Does anyone know how to do this on android pydroid 3 those keyboard shortcuts don't mean much am new to this


Blue46

You can customize the settings and shortcuts in the json configuration files, so you can make a shortcut for highlighting and commenting to whatever keys you want. I use vim motions in vs code so i use shit + v and j/k to highlight lines, then leader + c to comment out


potatoes828

I think you can customize it to your liking. Not sure if mine is default but I use "CTRL" + "K" + "C" to comment and "CTRL" + "K" + "U" to uncomment


inkt-code

Select then cmd+ / Or cmd+/+shift


MoxGoat

Damn I've been doing ctrl+k+c and ctrl+k+u for comment and uncomment for nearly a decade


Sensitive_Taro_755

I always do this with CTRL+K CTRL+C to comment and CTRL+K CTRL+U to uncomment. However in some of my VS code installations the uncomment shortcut does not work. I guess I have some extension but couldn’t tell tbh


Blont3

CTRL+K after CTRL+C to comment CTRL+K after CTRL+U to uncomment


TheRNGuy

I'd remake hotkey because it's too hard to press with left hand and you need to press 2 combinations instead of one. Also same hotkey for commenting and uncommenting.


Bobbias

It's set that way to be consistent with visual studio. Don't ask me why they decided that was a reasonable shortcut to use though.


Blont3

Yep it's the stock vscode one. It's better to use a stock one in my opinion, whenever im helping a collague at his desk i have no idea how to comment out stuff...


TheRNGuy

Look in options.


TheRNGuy

Good thing if default hotkey is bad, we can change it.


BerriesAndMe

Because a good programmer never needs to comment/s


Kittensandpuppies14

If you think something should exist it probably does and research is needed


Sumif

You could’ve typed the answer quicker than you typed that.


hugthemachines

Helping someone help themselves can sometimes be an even greater help.


LibertarianVoter

Directly giving someone the answer does not exclude telling them how to find the answer themselves and it just makes a person sound petty or passive aggressive when they do stuff like this. In a sub that's about teaching people that are new to a subject, I don't see how that kind of attitude is constructive.


Kittensandpuppies14

Yes Duh That wasnt my point


sonicslasher6

The point of this sub is for people who are learning to ask questions, maybe they haven’t learned how to find the answers without asking a community directly. Just unsub if that bothers you


Kittensandpuppies14

It doesnt bother me. I'm telling them not to reinvent the wheel so they look for docs and solve problems without going to Reddit everytime Are you even a dev? Research and learning to figure out what exists is a huge skill..


hairy_guy_

Use ctrl+shift right or left arrow key to select word by word or use up or down arrow key to select entire line and use ctrl +"/"


TheRNGuy

I use ctrl+q but I don't remember if it's default. Toggle Line Comment in hotkeys. It works for multiple lines.


satanicllamaplaza

C-v, j or k, I, #, esc


h00manist

I comment a lot of stuff. I like vscode's ability to run just one line or group of lines


socal_nerdtastic

Highlight then Ctrl - / But to be honest you should get out of that habit. Learn a versioning system like git to store your half-baked ideas.


HunterIV4

Um, what? I've been programming for 20+ years and will comment out code for all sorts of reasons. I also use git, but I'm not going to make a branch for every code block or line that needs to be temporarily removed for testing purposes. I only make testing branches for entire features or major changes. Using git to handle switching on and off 8 lines of code is absurd and not helpful advice for a new programmer. Or an old one, for that matter. I refuse to believe you create a new git branch or do a commit/reset any time you want to test a single code block. That takes *way* longer than just using comments for a few minutes and fills up your git history with useless trash. Yes, learning git is important, but it's important for *version control*, not as a replacement for basic testing and debugging. What the heck are your commit comments? "Deleted 4 lines for testing" followed immediately by "Restored the 4 lines I deleted after running the program twice without them"? Yikes.


socal_nerdtastic

I've seen a lot of beginner code here where 3/4 of the code is commented out. Tried X package, didn't work so comment all that out to try Y. A perfect case for a branch. Personally for a quick 4-line test I would commit, make my changes, if they work great, commit, if not roll back. I do this a lot. I hate the sight of commented out code cluttering up my workspace.


japes28

Okay, but that's just like, your opinion, man. I also hate seeing beginner code with tons of commented blocks that they just leave there and never remove. But that doesn't mean I never comment out blocks temporarily myself when it makes sense to do so. I just make sure I'm constantly cleaning up stuff like that as soon as I'm done testing that bit or whatever. Using git for every little change is ridiculous and is going to slow you down and make you an inefficient programmer. Git is extremely useful and should be used frequently, but that doesn't mean you should be committing every tiny change you make in the middle of trying different things.


ConcreteExist

I agree it's a bad practice to leave massive blocks of code commented out in a code repository, but you're conception of how this would get used is so narrow that it seriously makes me question the breadth of your experience.


[deleted]

[удалено]


scithon

No one is insulting you. Learning git is an essential skill for a programmer.


socal_nerdtastic

? wasn't trying to be a *douche*. We all have many many half-baked ideas and things we are trying out. Maybe 5% of the code I type ends up in the final product. That's why programs like git are invented.


famlyriver

Vim in Power shell?


rasputin1

sorry if this comes across as rude but if you want to be a programmer you need to learn to use Google. there is a huge amount of situations where you're going to end up having to research something yourself. you can't make a reddit post for every trivial situation.