“Let’s not talk about Vim”, old, senior and hardcore developers for checking: do you use such combinations of VS Code? If you are just starting to program, flying into IT on a Python course jet, or just don’t know anything about VS Code hotkeys, maybe you will definitely need a couple of combinations 🙂
All combinations are described for VS Code on Windows
↓ / ↑ / ← / → – arrows down, down, etc.
LMB / RMB / MMB – left, right, middle mouse buttons, respectively.
Shift + Tab — move the tab stop one step to the left. If you write in Python, then a tab or four spaces is your constant companion. But few people know that it is enough to put the cursor anywhere in the line, press Shift + Tab and voila, the entire line is shifted to the left by “one tab”.
Ctrl + / — comment out or uncomment a line. VS Code will figure out what programming language you are using, and at the beginning of the line will set or remove the required character for the comment. The place where the cursor is on the line is unimportant.
Shift+Del – delete the entire line. Now you do not need to select the entire line with the mouse and then press Backspace. You don’t need to select the entire line. Is it true!
Alt + ↑ / ↓ – move the line with the cursor up or down. Just try it and feel how convenient it is. You know the joke “you only have to put on underpants once in winter and you can’t stop”? So it’s worth only once to move the line like this, and you can’t do it any other way!
Shift + Alt + ↓ / ↑ – duplication of the line with the cursor down. Depending on ↓ or ↑, the cursor will remain on the current or new line. Now you can do without Ctrl + C, although no, you can’t =)
F2 – rename the variable. Please note that all variables with this name are renamed only inside the block, not inside the entire open file. Often you need to rename a variable that is already used in several places in the function, and then either manually place the cursor in the right place, or put the cursor on the variable and press F2.
F12 or Alt + LMB on a variable – go to a variable or parent class. PyCharm is often talked about as if only it can fall into parent classes to see what attributes we can override by inheriting from it; but so can VS Code.
ctrl+d – highlights the word on which the cursor is located. The next press on D (holding Ctrl) select the next identical value in order down. Here you are writing a function, and you need to highlight the closest values of ‘name’. Easily! You can select all occurrences of a word like this – Ctrl + F2. The good news is that the cursor is at the end of each selected value and you can immediately edit it!
Ctrl+L – selects the entire line. Whole. Copy-pasting is even easier now, isn’t it? =)
Ctrl + Alt + → — split the workspace and move the current tab to the right. Ctrl + Alt + ← brings the tab back. You won’t believe how convenient it is to see, for example, models.py And views.py near.
And now the unobvious, but amazing possibilities. Menu → File → Settings → Keyboard Shortcuts (Ctrl + K + Ctrl + S), enter the required parameter in the search bar and click on the result with the mouse, then press the necessary keys to set the custom settings and enjoy. Commands to definitely try:
editor.action.jumpToBracket – jump to the matching bracket, I have it set to Ctrl + Q. First jump to the nearest bracket, and the next press moves you to the matching bracket and so on. Often we need to end up either at the beginning of the brackets or at the end. And clicking with the mouse or arrows is not always convenient. Now one click is enough and you are at the right bracket.
editor.action.selectToBracket – select everything inside the nearest brackets and the brackets themselves, I have it Ctrl + Shift + Q. How many mouse clicks, how many errors, highlighting inside the brackets with the mouse or Shift + arrows. And now you can simply select everything accurately and quickly with one click.
I would be grateful for any interesting and useful hotkeys, write in the comments what you liked from mine, and what do you use yourself?