Not quite sure whether I'm using the right terminology here, but Netbeans has a very nice feature where e.g. if you start typing for it will offer to write a code fragment looping over an array or list, basing it on the name and type of an array or list variable actually in scope.
If more than one such variable is in scope it will guess, sometimes correctly and sometimes not.
Is there a way to aim this feature at the correct array/list variable?
You can do that like this:
Type fore and press TAB. This will generate the for each loop.
The loop variable is selected. Press TAB again to select the list variable.
Finally, press CTRL+SPACE, select a different list variable, and press ENTER.
(Tested with Netbeans 8.0)
In netbeans terminology, it is called code templates (many editors call it code snippets). You can customize them also by going to tools > options > editor and select required language from the dropdow.
Related
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!
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?
Some of my variables are huge (include tables with so many rows). When I try to see the variables via variables view in Eclipse, it shows a part of it, not the all. So, I need to use system.out.println("myVariable"); to see, what my variable contains, and this not an effective way.
Is there a way to get over this? Or do you offer a better solution than sys.out.println?
The best I would suggest is to use the display view:
menu -> window -> show view -> debug ->display
inside the display view, type the variable name, right click and select display. Still if short, use the sysout statement there, and again, right click and select display.
Hope this helps.
In Variables window we have grid with list of variables and a field with variable signification below. Right click on this field => "Max Lenght ..."
When I first learned Java, I was using an IDE called "BlueJ." It had this feature called "Scope Highlighting" which made it very easy to read blocks of code. Now I've moved on from BlueJ and began using Eclipse. I'm currently in the process of customizing Eclipse to my liking and would like this Scope Highlighting feature inside Eclipse.
I've searched everywhere for an answer on how to do it but I cannot find any information pointing to a solution for doing it in Eclipse.
Here's a picture to demonstrate what Scope Highlighting looks like:
I think the best option for you is EditBox, a scope highlighting plugin for Eclipse:
http://editbox.sourceforge.net/
I'm afriad that closest you can get is Shift + Alt + arrow_up
It is selecting wider block of code. pressing this few times will give you very similar result to what you are searching for. I use it often.. it is useful, also for refactoring.
EDIT: As #j2emanue said: you can just double click the delimiter (like a bracket) and it will highlight the entire scope.
you can use Shift + Alt + arrow_up but many people dont realize you can just double click the delimiter (like a bracket) and it will highlight the entire scope. Try double clicking your if statements bracket for example and watch eclipse highlight the entire scope. It works with any delimiter. so you can use parenthesis as well.
as a side note: if your using intelliji checkout this plugin works great: https://github.com/izhangzhihao/intellij-rainbow-brackets#screenshots
This isn't exactly what you're after but you can put your cursor in a method and then click the Show Source Of Selected Element only button on the toolbar. Your editor gets reduced to just that method. Click again and your back to your entire file.
I doubt eclipse does have the same function as blue j.The best advise I can give you, is to change your theme to your liking which would enable you to easily select and highlight the block of code...and to customise your theme , go to http://eclipsecolorthemes.org/. ....
If you still have a problem, go to http://codejava.co.uk/contact.html and send your email.you can create a dummy one if want, then I will send you XML files I use for my eclipse themes.
can Bracketeer do this ? its an eclipse plug in ..
http://marketplace.eclipse.org/content/bracketeer-java-jdt#.UK6sY4fAdLc
Maybe you will also like the VSCode extension "Blockman". It highlights nested code blocks based on curly/square/round brackets, html/xml tags and Python/Yaml indentation. (I am the author of Blockman).
.
https://i.ibb.co/31F0rm9/vscode-blockman-intro-leodevbro-extension3.png
.
.
is it possible, in Eclipse, to mark certain lines with Shortcuts and be able to quickly jump to those lines?
Example: Let's say I have maintenanceHeavyMethod() at line 120 in my class, gameLoop() at line 800 and some listener at line 1460.
I'd like to f.ex. press CTRL+SHIFT+1, 2, 3 etc. to mark those positions, and then use f.ex. CTRL+1, 2, 3 to immediately jump to them. I don't like split-screens etc, but I need to jump around when writing.
Is there such a feature?
I'm using latest Eclipse to write Java-programs.
You can add Bookmarks in your code. Select the code fragment you want to bookmark and then go to Edit > Add Bookmark... (also possible via the menu available with a right-click in the left hand column of the editor, like breakpoints).
Then, add the Bookmarks view. Select Window > Show View > Other... > Bookmarks and you'll get something like this:
Sadly, I don't think you can bind a shortcut to a particular bookmark.
Just in case, the shortcut to jump to a particular line is CTRL+L.
That would be best taken care by mylyn:
Define a task with this three method, and you will be to see only those 3 in the package explorer view
To jump to a particular method, I use ctrl+o and then start typing the method. If you're a proficient typist, this shouldn't take any longer; keep in mind that you only have to start typing the name of the method.
Unfortunately this isn't a proper solution for jumping to a line of code within a method.
You can jump to methods by using the outline view. Outline view shows all the Methods, Fields, and Inner-Classes (and their methods and fields and inner-classes...etc) of the source file you currently have open. I personally prefer this method, unless I have a stacktrace and know which line I want to jump to, in which case I use ctrl+L.