Eclipse editor code editing - java

First of all, I was unsure what the title of this question should be so I just gave it my best shot. I just started using Eclipse as my IDE, it's a great IDE and all but I get annoyed when I highlight a portion of code to be edited or replaced, any code after it gets deleted. So for example:
System.out.println(theScanner.nextLine());
I want to replace nextLine with nextDouble. I would highlight nextLine and type in nextDouble but then the ()()(); would be erased and I would have to type them in again. Is there a way to fix this?

Click Windows > Preferences. Type content assist in search box. Select Completion overwrites option as shown below
Keep cursor after character t then press Ctrl + Space.
Then type d then select nextDouble method press Enter

Related

Is it possible to tweak the settings so it automatically places quotations when using System.out.println()?

I am using java on Intellij and I wonder if it is possible to make it so that it automatically places quotations System.out.println(here);
Thanks
Yes, it is possible.But a bit tedious. (EDITED)
ECLIPSE
you need to know that Ctrl+space opens options for autofill.
you need to create a simple template at
Window>Preferences>Java(dropping menu)>Editor>Templates>New...
In the open window at Name type: Syso
at Pattern: System.out.println("")
Make sure the checkbox Automatically insert is on.
Apply and close
Now every time you type Syso and hit Ctrl+Space there will be first option
of autofill with quotations. Profit.
oof, didn't notice about Intellij , my bad. Thought about Eclipse. Well here is one for Intellij
INTELLIJ
I believe the Intellij version of cntl+space is Tab button
Go to Settings>Editor>Live Templates
Pick any template and press Plus icon. Choose Live Template
In abbreviation type your desired word (I would put: Syso)
In Template txt type : System.out.println("")
Make sure the box with Reformat according to style is checked
Now every time you type Syso you can hit Enter and have PROFIT!

Replacing a string with classname for multiple files in eclipse [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed last month.
Improve this question
How can I search and replace a String in all files of my current project?
Let's say I have the string "/sites/default/" now I want it to be "/public/sites/default/", but there are almost 1000 files.
Goto "Search"->"File" from menubar at the top left
Enter text, file pattern and projects
Click "Replace..." button at the bottom
Enter new text click ok
Voilà...
Depending on the file type you are focused on, Ctrl+H will open up different types of search screens.
A more consistent hotkey would be using the Alt method: Tap Alt, then A, then F.
Efficient Order of Operations:
Ctrl+C the text you want to do the replacing (if available)
Highlight the text you want to be replaced
Tap ALT, then A, then F. Brings you to File Search. The selection from (2) will auto-fill the search box
In the “File name patterns” input box, type in “.java” for replacing all Java files or type in "" to replace in all files
Click “Replace…”
Ctrl+V (Paste). Or type in the value you want to do the replacing
Enter
You can find more details in my blog post: http://blog.simplyadvanced.net/android-how-to-findreplace-in-multiple-files-using-eclipse/
Use Ctrl+H for opening Eclipse search dialog, select appropriate search tab and select "Replace..." to get you to the "Search and replace" dialog
Strange but it is a two step task:
Search what you want
In the search tab right click and select replace , or replace all:
A demo at:
http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html
Tonny Madsen said it right, but sometimes this is too simplistic.
What if you want to be more selective in your replacements since not all replacements are correct for what you're trying to do?
Here's how to get more granularity to do the replacements only in certain folders, files, or instances:
First, do like he said:
Click Search --> File... OR press Ctrl + H and choose the "File Search" tab.
Enter text, file pattern and choose your Workspace or Working Set.
Then:
Click Search
When your results come up, make some folder, file, or instance selections by Ctrl + clicking on the ones you'd like to select. Ex: here's my selection. I've chosen 3 instances, 1 file, and 1 folder:
Now, right-click on your selection and go to --> Replace Selected.... Here's a screenshot of that:
Enter what you'd like to replace it "With". In my case you can see it says it is "Replacing 190 matches in 4 files". Now click OK.
Voilà!
References:
Here's the tutorial I came across that taught me this: http://www.avajava.com/tutorials/lessons/how-do-i-do-a-find-and-replace-in-multiple-files-in-eclipse.html?page=2
ctrl + H will show the option to replace in the bottom .
Once you click on replace it will show as below
There is an option in search => file and shortcut is Ctrl+H. Go for further refer follow link. This is work fine with Eclipse Neon
Is there a way to find/replace across an entire project in Eclipse?
If you want to replace two lines of code with one line, then this does not work. It works in notepad++. I end up open all files in notepad++ and replaced all.
Ctrl+F gives me Find/Replace dialog box.
Or you can,
First Alt+A
Next Alt+F
Then press on Replace button.
If non of them worked:
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.
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

Eclipse custom hotkey - print current line to standard out

Eclipse has a useful hotkey to assign current line to a local variable - when I type for instance:
Math.random()
and press ALT + SHIFT + L (Extract local variable), I can quickly change the line to
double random = Math.random();
I would like to use the same trick for printing it to std out, so that the Math.random() is being changed to:
System.out.println(Math.random());
Currently the fastet way to to this is to type syso and use content assist to use a template, but that requires manual copy pasting. Anyone knows a better way to do this?
Two options come to my mind to achieve your goal, but both of them require the selection of statement first.
After you select statement, press CTRL+SPACE, then type syso and hit Enter.
Selected statement will be placed inside System.out block:
System.out.println(statement);
Also you can prepare eclipse template (Window->Preference->Java->Editor->Content Assist->Templates), and give it some name:
System.out.println(${line_selection});${cursor}
After you select statement, press ALT+SHIFT+Z or select menu option Source->Surround With (also in context menu). Template you have created should be there so select it. Selected statement will be wrapped inside desired block of code.
As far as I am aware there is no shortcut available from the keys section of preferences. Is content assist really not fast enough for you in this case?

shortcut for system.out.println in sublime text 2

I want to have shortcut commands in sublime text 2.
I want to simply type sopl and press tab to generate System.out.println('text'); with the word 'text' selected and ready for me to replace it.
I want to simply type sop and press tab to generate System.out.print('text'); with the word 'text' selected and ready for me to replace it.
I have installed SublimeJava plugin but apparently there is no such short cut
You're looking for pl<tab> for System.out.println(|); and p<tab> for System.out.print(|);. It doesn't put the 'text', but it does put your cursor in the right place to type. Also note that, like Eclipse or IntelliJ, when you expand a Snippet, Tab will continue to move you through the positions in the Snippet until you've filled in all the blanks.
These are called "Snippets", and you can find them under Tools -> Snippets.... You can add new ones with Tools -> New Snippet....
it is very simple, just go to Tools>Developer>New Snippet.. remove all the code there and copy paste the below code...
<snippet>
<content><![CDATA[System.out.println("${1:text}");]]></content>
<tabTrigger>sysout</tabTrigger>
<scope>source.java</scope>
</snippet>
now press ctrl+s and give some name (make sure that you're saving file with .sublime-snippet extension) and click on save.
now open any .java file and type sysout and press tab that is it...
you can also refer this article for more info..

Eclipse text cursor has changed and editor behaves differently

I pushed a magic button and now my cursor (the blinking thing that shows where you type) split itself and now Eclipse is acting like a plain text editor/like Microsoft Word. The cursor, which usually looks like "|", now looks like "¦" (what Wikipedia calls a 'broken bar' or a 'parted rule' rather than a normal 'vertical bar').
I just want to know how to get Eclipse to act normal again, and what I accidentally did so I don't do it again.
It sounds like you have accidentally switched from Smart Insert mode to Insert mode.
Press Ctrl + Shift + Insert or tick Smart Insert Mode on the Edit menu to switch back.
Smart Insert is the feature that automatically insert closing quotes and brackets when you type the opener and places semi-colons at the end of the line when you press semi-colon (if you have the preference for that enabled.)
Maybe you pressed the insert key, which will change the Eclipse editor to Overwrite rather than Smart Insert (see the info bar at the bottom of the editor), and will change the cursor to a block rather than a vertical line?
Update: Thanks for clarification - see mikej's answer which is correct. I'll leave this answer in case anyone has the similar, related problem that I describe.
Just double click on "Smart Insert" / "Overwrite" in eclipse status bar
For reference, I am adding image.
If nothing works, restart eclipse. That is what I did !
Just click
Toggle Vrapper Icon in Toolbar..
That may causes some issues like these. Because I'm also faced the same issue until today.
Please refer the below images to get clear idea about this.
Make sure that it is in disable mode in status bar
On my windows computer I press Shift + 0 but the zero has to be on the numeric keypad not the top row numbers.
Shift + 0 toggle my cursor.
#Jeremy by saying " I have a vertical line with a gap in the middle of it, like the character above the forward slash " i guess you are referring to the ' Pipeline 'symbol, the one you use to denote' OR ' in programming languages. As people already answered, you are in Raw Insert Mode (as opposed to Smart Mode) so try Edit->Smart Insert Mode (Ctrl+Shift+Insert by default).
For more info you can visit this thread http://www.eclipse.org/forums/index.php/t/53833/
And remember, the symbol is called 'Pipe' symbol or 'Pipeline' symbol.
I also had same problem, you can fix this by pressing just INSERT button on keyboard (on windows platform) also.
It worked for me.
or you can restart your eclipse.
I've encountered this symptom in Eclipse 3.7 before. And after I restarted machine, it disappeared.
If your cursor symbol is " + " then press Alt+Shift+A.
or else we can use Edit menu options ==> Toggle Block Selections
If you are using spring tool suite then you can double click on highlighted Smart Insert . Some keyboards do not have insert button.
enter image description here

Categories