How to print out highlighted text in Eclipse? - eclipse

I was wondering if there is a way to print out highlighted text in eclipse by using shortcuts.
So say we had
int number = 2;
number //highlight number + some key combination to turn -> System.out.println(number);
Thanks in advance!

Select number, hit Ctrl+Space, type syso and hit Enter.
The trick is to trigger the content assist (Ctrl+Space) when something is selected and then type the beginning of the template (in this case syso) and not the other way around (not syso and then Ctrl+Space).
See this #EclipseJavaIDE tip:

Related

Partial autocomplete of the suggestions given by vscode?

Is it possible for the autocomplete feature of vscode to accept only part of the suggestions on Tab?
Basically, we can specify the word separators characters in settings but the autocomplete feature seems to ignore these and replace the complete full word either way.
What I want, for example, is that by specifying the word separator "_" the autocomplete won't replace the full suggestion but only until this character which should effectively be considered the end of the word.
For example, having semi_completions_foo() declared and having written only the initial "se".
"se" + Tab -> "semi_"
"semi_" + Tab -> "semi_completions_"
On the other hand by pressing Enter the full suggestion would be accepted.
"se" + Enter -> "semi_completions_foo"
Is this already implemented?
This is currently not supported by default as of VS Code 1.35 but is tracked by this feature request.
However VS Code does support tabbing through suggestion alternatives after you accept a completion with tab. Just press tab again to switch to the next suggestion from the list.

How can I convert tabs to spaces and vice versa in an existing file

I cannot figure out how to do this for the life of me apart from doing a find-replace on 4 spaces and converting to tabs (Version 0.10.2). I can't think of an editor/IDE that doesn't have a specific feature to do this. Does VSCode?
Since fix of: https://github.com/Microsoft/vscode/issues/1228 the editor supports it out of the box. Simply go for:
F1,
indentationToSpaces or indentationToTabs (depending on your need)
Enter.
Another way to do it is click the current indentation (Tab/Spaces:n) on the footer which will open your indentation options where you can select what you want to do.
If you are trying to convert non-leading tabs to spaces (or vice versa) you can use a regex search and replace.
Press CTRL + H
Click the .* button to search using regular expressions.
To search for tabs enter [\t] in Find box.
Enter spaces in Replace box and perform your replace.
Search box in regex mode:
To round out these answers, I will add my take for converting each tab to n spaces.
Highlight a tab character
Use CTRL + F2 select all occurrences
Press SPACE n times
This is the easiest way to do this (going beyond only converting leading tabs).
Note that this does not convert consecutive tabs to k spaces. It converts each tab. For consecutive tabs please see my comment on jrupe's answer. You will need VS Code find and replace with regular expressions to accomplish that.
Select Replace: CTRL-H
Enter Horizontal Tab in Find box: hold ATL and type 009 on the keypad.
Enter a space(or more spaces) into the Replace box: press space bar
Press Enter to begin replacing Tabs with Space(s).
Press F1 and then type into textbox convert indentation to spaces or whatever you want ones
On Visual Studio, Ctrl+K+F did the trick for me.
Fast forward to 2020/2021, there are some extensions that will give us that conversion. I have just needed that functionality (hence I found this article), and searching for extensions I found:
geocode.spacecadet - providing both TAB->SPC and SPC->TAB, but not updated since 2017, with 1.3k installs, 3.5 review
takumii.tabspace - TAB->SPC, from 2020, 1.5k installs, no reviews
pygc.spacetab - SPC->TAB, from... wait, literally yesterday! (or today depending on your TZ), 2 installs, no reviews

Sublime Text autocomplete left column keyboard shortcut

The list of Sublime Text autocompletions can have two columns. If I press tab to select an autocompletion, it always uses the right column. What if I want to autocomplete using the left column?
This question is not language specific, but for example if I type "B2J" I get the suggestion "B2JointDef - box2D.dynamics.joints.B2JointDef". It's what I want, but I already imported "box2D.dynamics.joints.*" so I just need "B2JointDef". However if I press tab or enter, I get the whole "box2D.dynamics.joints.B2JointDef".
Do I need to use a more intelligent autocomplete package, or is there some way to get the left column?
Use SublimeJEDI. It should know that you have imported the package

eclipse multiple text selection like sublime text 2

is there an option or plugin for eclipse which would enable multiple simultaneous selections in the same editor.
In sublime text, selecting some text and then pressing Ctrl+d will add next instance of the same text to the selection if possible. After selecting the instances needed the editor has multiple carrets (not necessarily on the same or adjacent columns and rows). In this mode it is possible to move all cursors forward or back simultaneously and to edit all instances of text simuntaneously.
I find this feature very usefull and miss it sorely in eclipse..
This Eclipse plugin attempts to provide this feature: https://github.com/caspark/eclipse-multicursor. From the README:
What is this?
A work-in-progress attempt to provide Sublime-Text-like
multi cursor support for text editors in the Eclipse IDE.
What works?
Multiple identical lines can be edited simultaneously using Eclipse
linked mode editing (similar to existing "rename in file"
functionality)
Next steps
"select next" functionality + associated editing using Eclipse linked
mode
"find next" + associated editing
editing of non-identical text / editing without using linked mode
split selection to lines
regexp support for find next
This feature is available in LiClipse.
See it in action (more towards the end of the video).
It supports linking with Ctrl+K, unlink with Shift+Alt+K, Ctrl+Alt+mouse double click to select words or Ctrl+Alt+Mouse to make a selection of a region (or just end lines).
Preferences>General>keys>Rename - refactoring
I changed the binding to command + shift + R when > Editing Text.
Sorry for bringing up an old question, stumbled upon it after searching google for the problem
Alt + Shift + A, then you can hold shift and use the cursor in multiple lines.
Like Ctrl+D I could not find, but like Alt+F3 in sublime (multiselects all matches), you can do by pressing Alt+Shift+R, or select text > right click > refactor > rename.
Must say that this does not work with any kind of text. It works with names of variables, functions, classes etc.
Tested on Eclipse 3.8.1
ALT + SHIFT + F worked for me.
You can see shortcuts for all here:
Goto -> Window -> Preferences -> General -> Keys and search for replace then you will see binding for Find and replace. In the bottom of that window, you can add your key to Binding text box. There you can add or edit any keys as shortcut.
If you want to replace selected word's matching words or find selected words, use below keys because you do not need to select all words in eclipse:
Ctrl+F gives me Find/Replace dialog box.
Or you can,
First Alt+A
Next Alt+F
Then press on Replace or Search button occurding to your need.

How to do multiple line editing?

I want to edit multiple lines in eclipse, but I can't find any short cut or Plugin. In Geany I just press ctrl+alt+up/down I can add / edit multiple lines.
Maybe this example can explain what I mean:
var text = "myname";
var addr = "myaddr";
var age = "myage";
I want to edit text above into:
var my_text = "myname";
var my_addr = "myaddr";
var my_age = "myage";
The text above is just a simple example, but sometimes I have many lines of words that I have to edit its prefix.
Press alt + shift + A to Toggle block selection (Toggle block / column selection in the current text editor), this will let you write vertically in eclipse, then you can easily do this.
Go to Window->Preferences.
Find for binding in text box surrounded by red box.
On OS X, the key combination for multi-line edits in Eclipse (or STS) is option/alt+command+A
You can try the following plugin,
https://github.com/caspark/eclipse-multicursor/releases
With this multiple occurrence of same text can be selected and edited. This is similar to multi select functionality available in editors like Sublime and Visual studio code.
The Eclipse 4.24 (June 15 2022) will integrate it (See https://bugs.eclipse.org/bugs/show_bug.cgi?id=576377):
Multi selection down relative to anchor selection (e.g. Ctrl-Alt-J)
Multi selection up relative to anchor selection (e.g. Alt-J)
End multi-selection (e.g. ESC)
Add all matches to multi-selection (e.g. Ctrl-Shift-Alt-J)
Multi caret up (e.g. Ctrl-Alt-Shift-Up)
Multi caret down (e.g. Ctrl-Alt-Shift-Down)
Thanks to eclipse contributor !
The Eclipse 4.22 (Q4 2021) equivalent of Geany would Alt+Click on the lines you want to edit in one go.
Eclipse now supports
Multiple text selection
Support for multiple selection has been added to Text Editors.
Multi selections allow most edit operations (text replacement or insertion, extend selection to next word or to next line, copy/paste...) to apply simultaneously on all ranges.
Multiple strategies are available to enable multi-selections:
Turn a block selection into a multi-selection using the To multi-selection command,
Add a caret with Alt+Click,
Use the new Select All button on the Find/Replace dialog.
So check if this would work in your case.
I know this is an old post, but I still want to share my way of multi select and editing. However this way is restricted to only the same variables across the file. Simply highlight the variable to edit, right click, choose Refactor->Rename. Then edit the variable and it will also edit the same variables across the file. Hope it helps..:)
Press key - { Alt + Shift + A } You will see A [+] symbol in IDE then use this symbol as drag