How to navigate to the last cursor position in Eclipse if it is in the same file and was not edited? - eclipse

I had used Eclipse earlier, afterwards I switched to IntelliJ for a while and now back to Eclipse. There is one thing from IntelliJ which I can't find in Eclipse: Navigating to the real last cursor position - even in the same file and even if the cursor was moved between the lines using the arrow keys on the keyboard or the mouse. IntelliJ is able to do it and I found it really useful.
For example:
I move the cursor using the keyboard's down arrow key successively on lines 10, 20, 30.
Now I am on line 30 and when I press Alt+left I would like the cursor to go to the line 20.
After pressing Alt+left again I would like the cursor to go to line 10.
After pressing Alt+right afterwards I would like the cursor to go to the line 20 again.
The following shortcuts are available in Eclipse:
Alt+left - it navigates back to the last cursor position in a different file, not to the last cursor position in the current file even if I already moved my cursor in the same file
Alt+right - it navigates forward to the next cursor position in a different file, not to the next cursor position in the current file even if I already moved my cursor in the same file
Ctrl+Q - moves the cursor to the last edit location
The latest version of Eclipse in which I tested the above-mentioned shortcuts: Eclipse Luna 4.4.0.
I found the following discussion about the same problem (lacking such functionality in Eclipse) which is quite old, but it seems that this functionality has not been implemented in Eclipse since that discussion in eclipse forum.
Does anyone of you know if this functionality will be implemented in Eclipse? Is there a plugin for Eclipse which provides such functionality of navigating back to the last cursor position?
Please note, that due to the reasons described above, I'm not satisfied with the solutions provided as an answer to this SO question 'How to navigate to the last cursor position in Eclipse?' or to the other SO question 'How to go back in Eclipse?'.

Go to Preferences / General / Keys. You'll be able to see or edit the bindings for:
Backward History: default is Alt←
Forward History: default is Alt→
You may also use those shortcuts (and see the key bindings) in the toolbar:
answered Sep 7 '12 at 8:27
Denys Séguret

There is Alt+left arrow and Alt+right arrow to navigate to previous/next cursor positions, and CtrlQ to go to the last edited position

Use bookmarks for that because there is no another way of tracking the necessary code lines. Here is the link about how to use bookmarks http://www.luisdelarosa.com/2005/02/16/eclipse-tip-use-bookmarks-to-track-important-places-in-your-code/
Screenshot of the aforementioned article's content in the link:

I use the side buttons of my mouse and it works for me

The key combination Ctrl + Q brings you back to the last locations, where editing was done.
Use Ctrl + L for an overview of shortcuts. See also Eclipse shortcuts or this Eclipse cheat sheet.

Navigate > Back (Alt+Left_Arrow) already allows to navigate back to previous cursor positions even in the same file. E.g. after you Ctrl+Click on a reference to a local variable (to go to the declaration), then Alt+Left puts the caret back to the reference.
Exlpanation source

Related

keyboard shortcut for go back to last edited position in Visual Studio Code

In Visual Studio Code, is there a keyboard shortcut to navigate (move cursor) to the last edited position (like in all Jetbrains products with Ctrl+Shift+Backspace)?
The CTRL+- shortcut moves to the last position (not the last edited position), which is less useful for me.
i am using with
Visual Studio Code
JetBrains IDE Keymap for Visual Studio Code:
Visual Studio Code
Version 1.23.1
Commit d0182c3417d225529c6d5ad24b7572815d0de9ac
Datum 2018-05-10T17:11:17.614Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architektur x64
Also see https://stackoverflow.com/a/71212026/836330 for new navigation commands in vscode v1.65. See that link for navigating to next/previous cursor locations (where the cursor was but maybe no actual edit there).
For last edited locations:
Go Forward in Edit Locations
"workbench.action.navigateForwardInEditLocations"
Go Back in Edit Locations
"workbench.action.navigateBackInEditLocations"
Go Previous in Edit Locations
"workbench.action.navigatePreviousInEditLocations"
Go to Last Edit Location
// acts like a toggle between current and last edit location
"workbench.action.navigateToLastEditLocation"
Associated context keys have been added to make assigning keybindings
more powerful:
canNavigateBackInNavigationLocations: Whether it is possible to go back in navigation locations
canNavigateForwardInNavigationLocations: Whether it is possible to go forward in navigation locations
canNavigateToLastNavigationLocation: Whether it is possible to go to the last navigation location
canNavigateBackInEditLocations: Whether it is possible to go back in edit locations
canNavigateForwardInEditLocations: Whether it is possible to go forward in edit locations
canNavigateToLastEditLocation: Whether it is possible to go to the last edit location
[EDIT]: v1.28.0 just added a command to go back to the last edited position, see release notes: navigate back to last edited position.
Navigate to last edit location
A new command Go to Last Edit Location
(workbench.action.navigateToLastEditLocation) was added to quickly
navigate to the last location in a file that was edited. The default
keybinding is
Ctrl+K Cntrl+Q
For Windows use Alt+RightArrow and Alt+LeftArrow.
Last Edited Shortcut
Cntrl+k,Cntrl+q
Last Cursor Movement
ALt+Arrow left

How can I navigate back to the last cursor position in Visual Studio Code?

What is the keyboard shortcut to navigate back to the last cursor position in Visual Studio Code?
The keyboard shortcut commands are Go Forward and Go Back.
On Windows:
Alt + ← ... navigate back
Alt + → ... navigate forward
On Mac:
Ctrl + - ... navigate back
Ctrl + Shift + - ... navigate forward
On Ubuntu Linux:
Ctrl + Alt + - ... navigate back
Ctrl + Shift + - ... navigate forward
I am on Mac OS X, so I can't answer for Windows users:
I added a custom keymap entry and set it to Ctrl + ← + Ctrl + →, while the original default is Ctrl + - and Ctrl + Shift + - (which translates to Ctrl + ß and Ctrl + Shift+ß on my German keyboard).
One can simply modify it in the user keymap settings:
{ "key": "ctrl+left", "command": "workbench.action.navigateBack" },
{ "key": "ctrl+right", "command": "workbench.action.navigateForward" }
For the accepted answer I actually wonder :) Alt + ← / Alt + → jumps wordwise for me (which is kind of standard in all editors). Did they really do this mapping for the Windows version?
This will be different for each OS, based on the information in Key Bindings for Visual Studio Code.
Workbench configuration:
Go Back: workbench.action.navigateBack
Go Forward: workbench.action.navigateForward
Linux:
Go Back: Ctrl+Alt+-
Go Forward: Ctrl+Shift+-
Mac OS X:
Go Back: Ctrl + -
Go Forward: Ctrl + Shift (⇧) + -
Windows:
Go Back: Alt + ⬅️
Go Forward: Alt + ➡️
To answer for your question, for:
Windows use Alt+← for backward, and Alt+→ for forward navigation.
macOS use Ctrl+- for backward, and Ctrl+Shift+- for forward navigation.
Linux use Ctrl+Alt+- for backward, and Ctrl+Shift+- for forward navigation.
You can find the current key-bindings in "Keyboard Shortcuts editor."
You can even edit the key-binding as per your preference.
There is an extension available named Code-Navigation for all the platforms. As an alternative to the keyboard shortcuts it adds buttons to the left side of the status bar.
To set your own keyboard shortcuts (even if that particular keyboard-combo is already taken) you can go to Code > Preferences > Keyboard Shortcuts and set them up there.
Open Settings: Code > Preferences > Keyboard Shortcuts
Find Go Forward and Go Back and set them to whatever you like.
If a key shortcut is double-assigned VSCode will tell you, and you can click-in and change/remove the other ones. eg. by shortcuts were already assigned to indent-in and indent-out.
eg. our main tool is Android Studio on a mac which uses cmd+[ and cmd+] for forward and backward). This is especially powerful with a cmd+click for drilling into functions. (so you can follow your code as if it was an Ariadne's thread in a Minotaur labyrinth. Does help! ( so you jump around the code, diving in and out of functions, and back between files.
For macOS:
⌘ + U: Undo the last cursor operation
You can also try Ctrl + -.
BTW, all the shortcuts are in Keyboard shortcuts for macOS. This is really useful!
Use Alt + ← / →
You can find all shortcuts in Key Bindings for Visual Studio Code.
Mac OS (MacBook Pro):
Back: Ctrl(control) + - (hyphen)
Back forward: Ctrl + Shift + - (hyphen)
As an alternative to the keyboard shortcuts, there is an extension named "Back and Forward buttons" that adds the forward and back buttons to the status bar.
vscode v1.65 is adding a number of new commands for navigating to the last/next edit location or the last/next cursor location.
An edit location means there was an actual edit, whereas a cursor location means that you visited that location but may not necessarily have made an edit there.
By default, editor navigation locations are added whenever you
navigate across editors but also when navigating within editors (for
example, when switching notebook cells or changing selection in text
editors). If you feel that too many locations are being recorded, new
commands have been added that reduce locations to either:
Navigation locations (for example when using Go to Definition)
Edit locations (whenever an editor is changed, for example when typing in a text editor)
from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_65.md
Cursor locations:
Go Forward in Navigation Locations
"workbench.action.navigateForwardInNavigationLocations"
Go Back in Navigation Locations
"workbench.action.navigateBackInNavigationLocations"
Go to Last Navigation Location
// acts like a toggle between current and last cursor location
"workbench.action.navigateToLastNavigationLocation"
Go Previous in Navigation Locations
"workbench.action.navigatePreviousInNavigationLocations"
Edit locations:
Go Forward in Edit Locations
"workbench.action.navigateForwardInEditLocations"
Go Back in Edit Locations
"workbench.action.navigateBackInEditLocations"
Go Previous in Edit Locations
"workbench.action.navigatePreviousInEditLocations"
Go to Last Edit Location
// acts like a toggle between current and last edit location
"workbench.action.navigateToLastEditLocation"
Associated context keys have been added to make assigning keybindings
more powerful:
canNavigateBackInNavigationLocations: Whether it is possible to go back in navigation locations
canNavigateForwardInNavigationLocations: Whether it is possible to go forward in navigation locations
canNavigateToLastNavigationLocation: Whether it is possible to go to the last navigation location
canNavigateBackInEditLocations: Whether it is possible to go back in edit locations
canNavigateForwardInEditLocations: Whether it is possible to go forward in edit locations
canNavigateToLastEditLocation: Whether it is possible to go to the last edit location
You can go to menu File → Preferences → Keyboard Shortcuts. Once you are there, you can search for navigate. Then, you will see all shortcuts set for your Visual Studio Code environment related to navigation. In my case, it was only Alt + - to get my cursor back.
While the accepted answer is correct, anyone using the Vim extension for VS Code may be frustrated by the fact that navigating backwards takes you through every single cursor movement you've made. This prevents "Go back" from working well for use cases like:
Go to Definition
Poke around at the definition for a while (i.e., move the cursor around)
Go Back to where you were in step 1.
With the Vim extension installed, you'll be stuck doing "Go Back" for every cursor movement you've made (and for me, that's enough to make it almost useless!).
Fortunately, the Vim extension implements jumplists well, so after using VS Code to jump to a new position (i.e., "Go to definition"), you can simply do CTRL+O to go back to the previous jump location.
Last Edit Position v. Last Navigation Position
Go To Last Edit Position:
Ctrl+k Ctrl+q
This was mentioned in sudormfbin's comment but not listed as an answer. This is what I want to do 99% of the time when I think "where was I now?". It is the easiest quickest way to get back to your last position without taking your fingers off keyboard to use the arrow keys and without installing extensions, etc.
Navigate Recent Cursor Positions:
ALT+ ← Back
ALT+→ Forward
Most of the other posted solutions refer to this - moving between "Navigation Locations", i.e., navigating between editor tabs OR within an editor (e.g., you move the cursor on one line, then click on a line 20 spaces above).
For navigating between editor tabs, instead of the above you can do Ctrl+Tab as it will sort all of the tabs in most recent order so you have option to go to others or just release and go back to the last used one. Also without taking fingers off keyboard.
With Visual Studio Code 1.43 (Q1 2020), those Alt+← / Alt+→, or Ctrl+- / Ctrl+Shift+- will also... preserve selection.
See issue 89699:
Benjamin Pasero (bpasero) adds:
going back/forward restores selections as they were.
Note that in order to get a history entry there needs to be at least 10 lines between the positions to consider the entry as new entry.
There are several ways to go back and options to go back in vs code.
To change any of the following things, go to command pannel by pressing ctrl + p and then after typing a >, type what config you need to change:
Then all you need to do is click on the Settings icon (as pointed by 2 in the image) and change the key binding to whatever you want.
Different options you have for going back:
Go to the Last Edit Location
Cursor Undo (meaning: go to last cursor location)
Cursor Redo (Opposite of above)

how to make my shortcut in eclipse IDE

I want to use a shortcut to move the cursor to the next line or previous line.
I can't find this Command in Preferences->General->Keys.
Are there any plugins that can do this? Or do I have to develop my own plugin to for that? If I have to develop it, which extension point should I use?
If I am understanding your question correctly then you should be able to set the Eclipse Key Mappings for Up Arrow and Down Arrow keys.
Search for "Line Up" and you will see
Line Up
Scroll Line Up
Select Line Up
These should already be mapped to Up/Down Arrow and Shift Up/Down Arrow, but if not (eclipse does mess up keyboard mappings from time to time) you can add them back or set them the way you want.

Ctrl-S moves the cursor near the top of the document in Eclipse

Why is it that every time I save my file in Eclipse with Ctrl-S it moves the cursor to the top of the page I'm working on? Coincidentally, it moves the cursor to the top of the JavaScript section of an HTML page I am editing. It's really annoying. How do I stop it?
Yep, was plagued by the same annoyance. In the eclipse preferences, select javascript then editor. On the editor preferences page there is a box, checked by default, called "Smart caret positioning in JavaScript names (overrides platform behavior)". Uncheck it.
I've got into the habit of hitting ctrl+Q immediately after ctrl+S
This brings you back to the last edited location.
Not so much a solution as a workaround, but it has stopped me pulling my hair out nonetheless.
S.

How can I go to the next Eclipse marker (e.g. build error) using the keyboard?

Suppose I make a method signature change that breaks several callers, and I want to review the call sites manually to update them.
Once I change the signature, my "Problems" view shows, say, a dozen errors.
What keys can I hit to navigate through them while leaving the keyboard focus in the editor for fast fixups?
(It's been a while, but I think the Visual Studio equivalent is F8.)
Note that this question does not duplicate Eclipse: How to go to a error using only the keyboard (keyboard-shortcut)?, as that one seeks to navigate only between markers in the current file. In this case, I want to go to the next error regardless of which file it's in.
("Marker" is the general Eclipse term for errors, warnings, etc.)
The best I've come up with so far is Ctrl + F7 to flip to the Problems view, then ↓ to pick the topmost error, then Enter to go to it (which returns focus to the editor).
Here's a way to move to the next error, regardless of editor, in one keystroke. It's not perfect, but it works until it's fixed in Eclipse.
Open a "Markers" view. Click the down arrow at the top right, and choose "Configure Contents". Uncheck the show all box, and create the view to show only the problems you want to see. You'll probably want to deselect "warnings" and "errors" as well. Save it.
Click the same "Markers" down arrow, and choose "Group By". Select "None". This is important because you don't want the parent tree level nodes to show, otherwise some of your "next" actions will take you to those, which don't represent an error.
In Eclipse -> preferences -> keys, search for "Markers". If there is not a keystroke bound to the Markers view, create one. I use Ctrl + Shift + M
Get a keyboard hotkey tool like AutoHotKey (for PC's) or iKey for the Mac. I'm using iKey, but there are plenty of other Mac tools you can use. In your hotkey tool, define an action for the keystroke you want to use for "next error". I chose the standard CMD + .
For that keystroke/action in your hotkey tool, generate 3 keystrokes in the following order:
Ctrl + Shift + M
Down arrow
Enter
Of course, you'll want to change the first one to whatever you picked for yours. You'll probably want to restrict that action to be executed only when Eclipse is the current application.
Save that, create some compile errors, and test it.
Try Ctrl + 3 for Quick access popup window.
If the "Markers view" is not already visible, then type in "markers", in the searchbox on the popup window. Once you have selected it, it should stay available, when you press Ctrl + 3 the next time around.
I just had the same problem, after refactoring some parts of code. I had a lot of errors in different files and i had to go through all of those.
I used the following solution:
Mark all (relevant) entries in the Problems view.
To do this switch to the Problems view using Ctrl+F7 and select the entries with Shift+↓/↑
You can also select all entries using Ctrl+A
Open the marked errors by pressing ↵.
Every file containing at least one marked error will be opened.
The cursor will automatically select one error/file, as if you open only this specific entry
Fix the errors in the opened file.
Here you can use Ctrl+. to navigate to next error inside this file
Close the file using Ctrl+W when your done.
Eclipse will automatically focus the next file and you can go back to step 3
In my case this solution was much faster then switching to the Problems view each time.
There's an Eclipse bug entered for this that has an attachment that looks like it does what you want.
You could use AutoHotkey:
save the mouse position, send a mouse event to click on the arrow in CDT console and then return the mouse back to it's original location. Record the mouse coords with window spy or use autohotkey's search by image function (first capture the images of two arrows with printscreen into bitmaps).