DEV Community

Discussion on: 14 VS Code Shortcuts to Supercharge Your Productivity

Collapse
 
leob profile image
leob • Edited

You forgot what might be THE most powerful shortcut/feature in VSCode: navigate back/forward! (navigation history, not 100% sure what it's really called)

So, it works like this:

You move around in the code, e.g. you jump to a method, perform a search, go to the top of a file, go to the bottom of a file, open a new file, and so on and so on, anything that changes your "location" in the source code - now "navigate back" let's you instantly go back to the previous "places" where you've been (and "navigate forward" to move in the other direction).

I'd call it "super powers", if you learn only one shortcut, then learn this one.

P.S. and the second most useful feature is that you can override all of these keyboard shortcuts - I find some of them way too complicated and impossible to remember (especially having worked with IDEs before, which has similar actions but different keys for them) - so I just redefine a bunch of them.

Collapse
 
darrylnoakes profile image
Darryl Noakes

VS Code calls this "cursor undo/redo". I really need to use this more often 😄.
The default for undo is Ctrl + U. Redo has no binding by default.

Collapse
 
leob profile image
leob

Not sure if that's what it's called, but I've (re)defined it like this, in keybindings.json:

{
    "key": "ctrl+up",
    "command": "workbench.action.navigateBack"
},
{
    "key": "ctrl+down",
    "command": "workbench.action.navigateForward"
},
Enter fullscreen mode Exit fullscreen mode

The internal name is "workbench.action.navigateBack" and "workbench.action.navigateForward", and I've assigned "control-up" and "control-down" to it (left and right would have been more logical, but somehow that didn't work).

This is incredibly powerful and I have the impression that not a lot of people know or use it, it's kind of tucked away and doesn't even have default key bindings.

Thread Thread
 
darrylnoakes profile image
Darryl Noakes

Sorry, I mixed up the two. I found cursor undo/redo in the keybindings menu, and thought it was that. It is like a much more toned-down version of Navigation. It only changes your cursor position, and skips to the beginning of the file if the "history stack" is empty.

Navigation is so much better!, as it navigates between files, and works at all times, not just when an editor is focused.

My VS Code keybindings for Navigation:

  • workbench.action.navigateBack: Alt + LeftArrow (default)
  • workbench.action.navigateForward: Alt + RightArrow (default)
  • workbench.action.navigateToLastEditLocation: Alt + K (default was Ctrl + K, Ctrl + Q)
Thread Thread
 
leob profile image
leob

Ah nice, I didn't know about the other one, but yeah "navigation" is indeed brilliant because it also navigates backwards/forwards across files ...

Thread Thread
 
darrylnoakes profile image
Darryl Noakes • Edited

left and right would have been more logical, but somehow that didn't work

Ctrl + LeftArrow/RightArrow don't work because they are Windows keyboard controls (also in pretty much all OSes). They navigate to the left and right of words.
For example (| represents cursor):
"I am some tex|t." => LeftArrow => "I am some |text."
"I am| some text." => RightArrow => "I am some| text."

Thread Thread
 
leob profile image
leob

Yeah that's why I chose different key combos for nav prev/next :)