Owen Conti

5 Keyboard Shortcuts to Navigate Your Code Faster

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:

  • CMD with CTRL
  • OPTION with ALT
  • CTRL stays as CTRL

Preface: These shortcuts may not apply to some editors such as Vim, etc.

Delete line(s)

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.

  • VSCode default: Shift + CMD + K
  • My keybinding: CMD + D

I prefer my keybinding over the VS Code default because I can press it with just my left hand.

Move line(s)

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.

  • VS Code default: OPTION + up/down arrow key
  • My keybinding: same as VS Code default

I stick with the VS Code default for this one because it's what I started out using.

Go to line

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).

  • VS Code default: CTRL + G
  • My keybinding: CMD + L

I prefer my keybinding because "Line" starts with "L" so it's easier for me to remember CMD + L than CTRL + G.

Go back/forward

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

  • VS Code default: CTRL + -
  • My keybinding: CMD + [

Go forward

  • VS Code default: CTRL + SHIFT + -
  • My keybinding: CMD + ]

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.

Start/end of word

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._

  • VS Code default: OPTION + left/right arrow key
  • My keybinding: same as VS Code default

Bonus shortcuts!

I've included two extra shortcuts which are very similar to the Start/end of word shortcut.

Start/end of line

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:

  • CMD + left/right arrow key

Highlight characters as you use start/end of word/line

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":

  1. Use your mouse and double click "world" 🤮
  2. Use the start/end of word shortcut to quickly highlight "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.

Summary

To summarize what we learned today, here's what I recommend:

  • Delete line(s): CMD + D
  • Move line(s): OPTION + UP or DOWN ARROW
  • Go to line: CMD + L
  • Go back/forward: CMD + [ or ]
  • Start/end of word: OPTION + LEFT or RIGHT ARROW
  • Highlight characters with start/end of word: SHIFT + OPTION + LEFT or RIGHT ARROW

VS Code keybindings.json file

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];

Thanks for reading this article!

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.