Posted on under Tips by Owen Conti.
Here are 5 keyboard shortcuts you can implement in any IDE to help navigate your code faster.
I use VS Code as my IDE, but these shortcuts can be applied to any editor.
The keyboard shortcuts I list in this article are OSX specific, but they should transfer over to Windows if you replace:
Preface: These shortcuts may not apply to some editors such as Vim, etc.
Before you utilize a delete line shortcut, you find yourself highlighting an entire line and then pressing backspace or delete. This works, however a shortcut can make it much faster. This shortcut also works on multiple lines, if you have multiple highlighted.
I prefer my keybinding over the VS Code default because I can press it with just my left hand.
How often do you find yourself copy/pasting lines to move them up or down throughout a line? With this keyboard shortcut, you can simply use your arrow keys to move lines around.
I stick with the VS Code default for this one because it's what I started out using.
A lot of people don't realize almost all text editors have a Go To Line utility built in. This is really helpful when you are dealing with larger files and need to find a specific line (maybe from the result of a stack trace while debugging).
I prefer my keybinding because "Line" starts with "L" so it's easier for me to remember CMD + L than CTRL + G.
Let's imagine you have 5 files open and you're trying to follow the code flow between files. Now you want to go back to the previous file and re-read a line, but you can't remember which file it was or what line number.
This shortcut will move your cursor to where it was before/after, even across files. Think of it as an "undo/redo" for your cursor.
Go back
Go forward
I prefer my keybinding because it is the default in Eclipse, which is where I learned this shortcut. I also prefer the difference of [ and ] instead of using SHIFT as a modifier.
This one is a game changer. How many times do you find yourself holding down left arrow while the cursor slowly moves towards the middle of the line so you can fix a typo or replace a word?
With the start/end of word shortcut (sometimes called Cursor Word Start/End), you can quickly navigate one word at a time left/right on a line without holding arrow keys or having to use your mouse.
Note:_ underscores are considered part of a word while hyphens are not._
I've included two extra shortcuts which are very similar to the Start/end of word shortcut.
In addition to the start/end of word, you can also quickly go to the start/end of a line by using CMD instead of OPTION:
Let's say you have some code that looks like this, and your cursor is at the end of the word "world":
1const name = "Owen";2console.log(`Hello world!`);
Now you want to replace "world" with the
name variable. You have two options to quickly select "world":
Using the shortcut, you would hold SHIFT + OPTION and then hit the LEFT ARROW key to highlight world. This would highlight just the word "world", which you could then replace with the variable
name.
To summarize what we learned today, here's what I recommend:
Here's a copy of my
keybindings.json file for VS Code if you want to take a look at the rest of my keybindings:
1[ 2 { 3 key: "cmd+d", 4 command: "editor.action.deleteLines", 5 when: "editorTextFocus" 6 }, 7 { 8 key: "cmd+t", 9 command: "workbench.action.quickOpen"10 },11 {12 key: "cmd+[",13 command: "workbench.action.navigateBack"14 },15 {16 key: "cmd+]",17 command: "workbench.action.navigateForward"18 },19 {20 key: "shift+cmd+b",21 command: "workbench.action.tasks.runTask"22 },23 {24 key: "alt+`",25 command: "workbench.action.terminal.focusPrevious"26 },27 {28 key: "ctrl+cmd+a",29 command: "-extension.align",30 when: "editorTextFocus"31 },32 {33 key: "cmd+\\",34 command: "workbench.files.action.showActiveFileInExplorer"35 },36 {37 key: "cmd+l",38 command: "workbench.action.gotoLine"39 }40];
Hopefully you found this article useful! If you did, share it on X!
Found an issue with the article? Submit your edits against the repository.