Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate back to the last cursor position with respect to *same* file in Visual Studio Code?

Alt+Left navigate backs to the last cursor position and if the last cursor position was in a different file then it navigates to that file.

But, I want to navigate to the last cursor position with respect to the currently focused file only. It is really useful when I have 2 split file editors and want to navigate back exclusive to each other.

Is it possible?


I hope you understand the question, let me know if further explanation is required.

like image 675
GorvGoyl Avatar asked Aug 22 '18 13:08

GorvGoyl


2 Answers

Basic Functionality

You can use the cursor undo / cursor redo commands via the command palette.

Undo also comes with a keyboard shortcut by default (Mac: cmd+u, Windows/Linux: ctrl+u), and you can configure a keybinding for redo.

Advanced Functionality

Note, however, that the file's cursor history is only saved while it has focus in an editor group. So if you have split editors, multiple focused files can have their own cursor history saved. And if the same file is opened and focused in two different editor groups, it has two different cursor history states.

But as soon as you focus another file in an editor group, the previously focused file will lose its cursor history (in that editor group).

The VSCode team is currently working on a variety of open issues to improve local history across the board, but I don't believe that saving cursor history for blurred (or closed) files is in the plans yet. If you need that functionality, you may want to create a feature request.

like image 94
jabacchetta Avatar answered Oct 11 '22 12:10

jabacchetta


Note, with VSCode 1.40 (Oct. 2019):

  • The Soft Undo command has been renamed to Cursor Undo
    This action is useful, for example when using Ctrl+D to select the next match and going one time too far, as it undoes only the last cursor state change.

  • Additionally, we now have added Cursor Redo, which redoes the previously undone cursor state change.

like image 42
VonC Avatar answered Oct 11 '22 11:10

VonC