You can modify, remove, and reset the keybindings for commands by right-clicking on a keybinding and using the available actions from the context menu. It lists all available commands with and without keybindings. To view and edit keybindings, you can open the Keyboard Shortcuts editor through the command “Preferences: Open Keyboard Shortcuts”. For example, I like to use Ctrl + Tab for switching between tabs in a group, in the section Keybindings for Panels you can see that I added a keybinding for switching between panels to match up with switching between Editors.
I had some wrist pain and it has certainly contributed to the alleviation of that over time.Īlso, a really nice thing to do is to use a keybinding consistently within VS Code for similar tasks. As you are changing your habits, it is probably best to do this slowly rather than as a big bang initiative! Think crash dieting here! For this reason, I think its best to think of shortcuts as an input into creating healthier habits. I add shortcuts to my repertoire over time when I see an opportunity, or encounter some friciton when doing something.
However, it may spark some ideas of how to adapt your own configuration. So, you probably do not want to copy it all verbatim. I think keybindings are something that are particular to individuals. You can copy it exactly if you wish, but keep in mind that some of the keybindings apply to extensions that I have installed. Here is my current keybindings.json, which I reference throughout. Then, I will dive into some keybindings that I use everyday. This is not intended to be a guide on keybindings in VS Code, there is a good guide for that already, however I will cover a few key points (pardon the pun) on adding and modifying keybindings that will ensure we are on the page. Well, most extensions do not have default keybindings! Since some of your most commonly used functionality probably lives in some extension or another, you would need to add your own keybindings to reap the rewards there! And there may be builtin commands that you want a shortcut for, but it has none or maybe there is one that is not to your liking! You will need to get your hands dirty at some stage!
You just need to learn some of these and put them to use (see keybindings references for Linux (US), Windows (US), macOS (US)). Visual Studio Code (VS Code) comes with default keybindings for many of its built-in commands. Perhaps you’ve left an important note to your colleagues or future self explaining some odd block of code.Keyboard Shortcuts (keybindings) can help you achieve tasks faster, and with less effort. But what if it’s a really useful comment? I would eventually either delete that code or remove the comments. Here, I’m commenting code, so it’s not that much of a problem. What if you want to comment multiple lines but leave some space before the code? Normally, Ctrl+K, Ctrl+C will leave the comments in a nice column like in the following example: public class Class1īut notice a few not-so-nice trends in that sample? For one thing, there’s the “missing” comment line with no // and the comment characters are right up against the code. Non-Keyboard Visual Studio Comment Shortcuts I’ll admit, it’s a bit easier on the eyes. It doesn’t, however, leave a space between the comment characters and your code this has been known to upset JS linters that like to see that space by default. If you’ve got the cursor on a line with no highlighting, it’ll just comment the line from the start of your code.
That all depends on what you’ve selected with your cursor. The comment shortcut will also lay down comments on a single line or multiple lines. It can comment in HTML, JavaScript, SQL, C#, CSS-you name it! Now, Visual Studio knows how to comment in several languages. And to round it out, the mapping for uncommenting is Ctrl+K, Ctrl+U. I’m going to stick to defaults, but later in this post, I’ll show you how to change those. This, of course, is the default shortcut for Edit.CommentSelection, which can be mapped to whatever you’d like. The most basic shortcut for creating a comment is Ctrl+K, Ctrl+C.