I'm after a feature in eclipse that allows me to allocate a shortcut to a line (say line number 55) then go somewhere else in the same file and hit the shortcut then IDE shows me the line 55. I have used this feature in Delphi IDE. Using CNTL + number keys[1,2,...,0] a shortcut to line where the curser is will be created. This shortcut only has effect within the editor and each opened file would have its own shortcuts.
Is there such a feature in eclipse? Is there any plugins out there which adds this feature to eclipse?
Regards,
Ali
By default there is no shortcut defined for this task.
I use to define my shortcuts in Eclipse in "Windows/Preferences/General/Keys" type bookmark in the filter text and select the commands you want to define the shortcuts.
My current shortcuts are:
Alt+Shift+B, Alt+Shift+A: Add Bookmark;
Alt+Shift+B, Alt+Shift+V: Show View (BookMarks);
But, I agree, still is not fast as the Delphi predefined shortcuts.
Update 1:
This plugin (or its sucessor) seems to offer the option. From their site:
Add a numbered bookmark at the cursor: Alt>+[digit]. This creates a
quick bookmark with the specified number using a "single" keypress.
Only one bookmark of the given number can be present in the workspace.
Setting the same number bookmark again will clear the earlier
instance.
Goto a numbered bookmark: Alt+Shift+[digit]. Moves to the bookmark as
it was set using Alt+[digit].
Update 2:
Tested (Eclipse Indigo) and it worked like a charm.
You can add Bookmarks to the code fragments you think are important to you in eclipse.
I referred this link for the same purpose.
I tried using the Toggle mark occurrences (Alt + Shift + O) button and also in Preferences -> General -> Editors -> Text Editor -> Annotations and setting the C/C++ Occurrences and C/C++ Write occurrences. But still when I select a word it won't highlight all occurrences of that specific word.
What I am using is Eclipse Indigo Service Release 2 in XP, with a C++ project.
You can try to activate Toggle Mark Occurrences with icon on Toolbar:
Preferences --> Java --> Editor --> Mark Occurrences
In General > Editors > Text Editors > Annotations
Check out options that are checked in Preferences -> Java -> Editor -> Mark occurrences. Then restart Eclipse.
Find the Preferences under Window,
In General > Editors > Text Editors > Annotations(1)
(5) is to select the color and press apply.
The standard "Mark Occurrences" functionality included in Eclipse that everyone recommends only highlights identifiers in editors of whatever language. For example, it won't highlight int in C editors, and it won't help at all in the Console pane.
So if you want to highlight ALL occurrences on ANY word in ANY Eclipse pane (kinda like Notepad++ does), try the Glance plug-in for Eclipse.
As of November 2017 Glance works for Eclipse Neon and Oxygen. There was a period of time in which Neon was unsupported, and a fork appeared, but it seems unnecessary now (and abandoned).
There are two ways to highlight all occurences. First is using Eclipse options, which is not very reliable, because in many versions of Eclipse it is not supported.
Second is using a plugin called Glance which is available in Eclipse marketplace. This is supereasy and effective.
First Method
In the toolbar, there is button for Toggling Mark Occurrences. So, once you selected the text/word whose occurences you wish to highlight, then click this toggle button.
Let's say this step doesn't work for you. Then, Follow this step:
Goto: Window ==> Preferences ==> General ==> Editors ==> Text Editors ==> Annotations ==> On right Annotations types box: Occurrences ==> Select all check boxes.
You can also go to Window ==> Preferences ==> Java ==> Editor==> Mark Occurrences ==> Check all the checkboxes.
Restart Eclipse and check if highlighting works.
If still doesn't work, then Go to Second Method
Second Method
From Eclipse marketplace, install Glance. Once installed, restart Eclipse.
Now select any word in your eclipse editor
Move focus to component where you want to search
Open Glance using Ctrl + Cmd + F shortcut on Mac or Ctrl + Alt + F on other platforms
Enter text you want to search
Use Enter or **Shift + Enter** to find next/previous match
Close search box using Esc
You can also customize Glance from Window ==> Preferences ==> Glance
For Eclipse Mars:
Window --> Preferences --> Check (Mark occurrences of the selected element in the current file.)
As shown if figure:
Go
Java> Editor > Mark Occurrences
Uncheck "Keep Marks when the section changes" then click Ok
Restart Eclipse.
This work for me.
If you go into the window-prefrences, select the language you want/are working with. Select the editor under this specific language and then there is a mark occurrences there that has some options. Where it says keep marks when the selection changes, for me this was checked. When I unchecked it the system started highlighting correctly.
For folks who are using a dark background with light font colors, you may want to check out the highlight color in Preferences -> General -> Editors -> Text Editor -> Annotations. Mine was defaulted to black, which does not stand out on a black background.
Glance does not work anymore, but in current Eclipse Versions (Eclipse 2020) you can
highlight any word by selecting the word and pressing CTRL+F. The word is now highlighted. In the small search input, you can toggle 'match whole word' and case sensitivity.
I'd like to complement the other answers - which work in Java editor only or require plugins - with a way to highlight all occurrences of any text (not just a word or identifier) in any editor of text files (e.g. SQL, CSV, HTML, TXT, Java, etc ...).
There is a standard/built in command called Find Text in File (under Window -> Preferences -> Keys)
By default it has no keyboard shortcut assigned. Simply give it a shortcut (e.g. Ctrl+Alt+S) select some text (not necessarily a word) and it will find and highlight all occurrences of that selected text.
It can also be invoked from the menu as Search -> Text -> File.
Enjoy 🙂
Click the word and hold until a popup appears as shown in the figure.
On the popup, there is a little right arrow, after clicking it, a new icon shows up.
Click that link to open preferences.
Once in preferences, select C/C++ Occurrences (it will be language specific) and select Include in next/previous navigation with Text as Highlighted.
This should enable the feature of highlighting all occurences of the selected word in the opened file.
How would one automate a commonly used search replace action in Eclipse?
My current workflow is as follows:
Double click on function bracket selecting function
Ctrl-F opening Find / Replace dialog
Type "foo." in Find box (alternatively can use pulldown menu but that is slower)
Type "bar->" in Replace box
Press Replace All button
Ideal macro would do all of the above bound to a single command.
From my search, it doesn't look possible in plain vanilla Eclipse, but perhaps there is a plugin which can do this?
Using: Eclipse Helios for C/C++ developers
Try the Practical Macro plugin.
There is even an example on the forums showing a Find/Replace macro definition.
Is there a command to replace a string of code with another in all .java files in an Eclipse project?
In Visual Studio there is a "Replace in all files" option that I can't seem to find in Eclipse.
Press Ctrl+H or look in the Search menu for Search>Search or Search>File depending on version. At bottom of dialog box, click Replace... There you'll find the replace in files functionality.
Press Ctrl+H or look in the Search menu for Search>Search or Search>File Search Tab. At bottom of dialog box, click Replace
I have tried the following option in Helios Version of Eclipse. Simply press CTRL+F you will get the "Find/Replace" Window on your screen
I don't know about command but just
press 'ctrl+h' the dialog that appears woulh have what you need
Select the word and press alt+shift+r then replace the word, it should reflect in all classes.
Is there any shortcut for surrounding any selection with a template from "Surround With..."?
In this special case, I defined a surround with brackets template... It would be a great enhancement to have such a shortcut.
Thanks for your help in advance.
The only shortcut I know about for surround templates
(that is for templates with ${line_selection} variable in their definition)
has been introduced in eclipse 3.2 (refined actually in eclipse3.2 M4)
It is the "Surround With Quick Fix" mechanism
(source: kano.net)
Assign a shortcut to Quick-Fix (CTRL-1 by default), and if your selection is eligible ((contains a line), all compliant templates will be displayed in the Quick-Fix dialog.
You will then be able to choose the appropriate surround template (like the one you defined).
Answer from #VonC is not working on Eclipse Kepler. Use short cut for show surround with quick menu.
Select one or more lines in java editor press Alt + Shift + Z then you will get the popup context menu as shown below(Menu items differ based on the region of selection).