Most developers spend the lion's share of their time in the development environment. But few use at least half of the opportunities that exist in the IDE, thus making a part of their work boring, monotonous, slow... No, it's not our way! We should use our main working tool to the full force, to squeeze the most out of it, and to move all the most uninteresting, repetitive actions to the shoulders of the program.
I do not want and will not describe the standard tips such as «supports PHP 5. *, CSS 3. *, SVN, Git, etc», «Light Smarty» and the rest of the obvious things. I would like to share some things that have repeatedly helped me in the netbeans customization, and are often left unnoticed or unused by colleagues (according to my observations and questions in Twitter). We start from far — from IDE setting.
Ivanna
Client Manager
Contact us, and we will share our case studies related to software development
Get a Free ConsultationNetbeans settings
Remove unnecessary
The default editor has not so much space left for the code. It’s full of different toolbars, additional windows, etc. When the monitor is way over two dozen inches – this would hardly be a kind of a problem. But when the IDE is used on a laptop / a netbook – it starts to annoy.
To begin lets reduce the icons for the main toolbar buttons:
vs
Even for larger storage space toolbar in the editor can be removed altogether via the context menu in the left panel of the editor.
In addition to all, let’s switch to full screen mode by hitting Alt+Shift+Enter. And one more commonly used keyboard shortcut: Shift+Esc – to maximize the active window, and pressing it again will return the same size window.
As a result of simple manipulations the useful area for the code has increased significantly.
Right away, in the course of reading the article, try these shortcuts in practice:
- first — you will see exactly how they work;
- secondly — more likely they will not fly out of your head till the end of the next paragraph =)
Code formatting in NetBeans
In 90% of cases IDE fully copes with the task, so let it keep doing this, not us.
However, in the editor, there are some problems with usability of settings of function’s formatting. And sometimes it can turn a long search just one setting to fix the indentation after the method’s description or add a line break. Here’s an example:
It seems everything is somewhat convenient because you can easily see which field is responsible for a correspondent place in the code. But, unfortunately, backlighting are added not by NetBeans but manually in a graphics editor. Well, as long as such a convenient functionality is not added to the editor — in case of necessity we have to peep at articles like these for formatting code netbeans.
Group multiline alignment in NetBeans
One of the reasons why I at one time did not always allow myself to apply an AutoFormat to the whole file was stray indents for arrays, etc.
But since version 7.1, they added support for group alignment.
Deprived of attention NetBeans features
Automatic delete of hanging spaces. These «invisible friends» can really spoil the nerves. Especially when working in a team.
And then such diff files in the counts appear where except for the gaps nothing has changed.
Call the settings window
, tab , at the very bottom . And instead of choose either , or . And be easy and forget about the extra spaces in your code, IDE will take care of everything.
Also there are several experimental options on the tab
and
I think there is no need to explain the purpose of each of them. On quite rather big projects in the Zend Framework I did not notice any problems with performance, so you should and even must use these features.
Further on I recommend to enable the option tag
or branch
will be displayed in the window of tree project for the libraries. The screenshot shows an example for the connected through svn:externals
from tags libraries.
There is the possibility to edit the format of these messages: http://wiki.netbeans.org/FaqSubversionCustomizeAnnotation
NetBeans color schemes
The default color scheme is not the best, so I think the tailoring of the standard scheme, or even its replacement by another one would be a necessary step to a comfortable development process.
Of premade schemes there is a port for NetBeans of fairly common theme Solarized.
It’s available in both light and dark version.
Solarized Colorscheme for NetBeans.
And another dark theme (Twilight) for Netbeans.
NetBeans plugins
-
Displays the current end of the lines in the file and allows you to change it.
http://plugins.netbeans.org/plugin/36810/show-and-change-line-endings - In the lower right corner the icon appears. It has an open / closed padlock that displays the current availability of a file for writing, and allows one-click change of this property.
- Plug-in for integration of PHP Mess Detector and PHP CodeSniffer into NetBeans and the instruction on installation and configuration:
- History for Clipboard.
-
Support ZenCoding for NetBeans.
https://github.com/lorenzos/ZenCodingNetBeansPlugin#readme
Use: tips&tricks
The first thing you need to teach yourself: to work without a mouse as much as possible. It’s much faster and more productive to work with the keyboard, and more, not to all functionality of IDE could be accessed through the menu items (or it’s hidden so deep you’ll get completely bored with your desire to look for it with the mouse again and again).
NetBeans hotkeys
The first thing you need to start — print a list of the main hot keys, (
) and pry into it until you reach the use of automatism. While now I do try to warm up interest.If you need to change the case of letters in a long word (variable, etc), what would you do? Reprint the word again? I don’t advice: just select the desired characters, press Ctrl+U, and then — U or uppercase, or L for the lower. And the button S (Switch) pressed after the combination Ctrl+U will change the register for each letter of the selected block to the opposite.
Put the cursor on a needed line or highlight the whole block, then hit Alt+Shift + ←, ↑, ↓ or → and it migrates easily in any direction. You don’t need to «move» code through the copy-paste. I like to move it, move it! :)
And if instead of Alt+Shift press Ctrl+Shift + ↑ or ↓, then the selected block will duplicate in the direction of the arrows.
Ctrl+Space — standard auto completion.
Ctrl+P — mapping of the arguments for the selected method / function / class.
Ctrl+Shift+Space — mapping of a pop-up window with the documentation (generated from the docking blocks).
Ctrl+G — jump to the line number ...
Ctrl+E — delete the current line under the cursor, or the selected block.
Ctrl+Q — move to last place of editing (to evaluate the usefulness — you need to try at work after an active refactoring, etc).
Ctrl+Shift+V — paste the code snippet from the buffer, already formatted (in accordance with the configuration described above).
Alt+Shift+J — selection of identifier. In fact it selects any word entirely, which now houses the cursor, and puts the cursor at the end of the selected line:
While writing the article I found for myself new and a very convenient shortcut of keys to quickly select a code block. Put the cursor, press Alt+Shift+. and with each pressing a little bigger block is selected.
A combination Alt+Shift+, does exactly the opposite — with each press decreases the selection.
P.S. To make it easier to remember this key combination (dot and comma somehow didn’t fit at all in my head), I got them remembered as Alt+Shift+> and Alt+Shift+< (select more / less).
Ctrl+Enter — after the line with the cursor new transfers of rows are added, the cursor itself remains in its place.
Shift+Enter — even if the cursor is in the middle of the line, after you press the combination the cursor will be transferred to the newly created line, the previous remains unchanged (as if you first pressed End, and then Enter).
For quick navigation without a mouse:
- Ctrl+0 — code editor;
- Ctrl+1 — Projects window;
- Ctrl+7 — Navigator window.
If you want to open any file, what will you do? A hand would reach for the mouse to open a folder-by-folder in the project tree, until it gets to the desired file. And that is in case you remember the place it is located. It’s too long. It is not always convenient. But it’s much easier and faster to find the file (or class) on its name.
Alt+Shift+O — Search for the file by name.
Ctrl+O — Search the file by the name of class it contains.
Moreover, it is not necessary to enter the file name in full:
Alt+Ins — code generator. Depending on the context, the content of the popup menu will be different. For example, we have a model with described properties, now we need to create a setter and getter for each of them. It is boring and tedious. Then let IDE make it. Select the item we need from the menu.
In the dialog box, select the properties for which we’ll generate a code.
And let’s admire the result.
Though hotkeys are not hung on many other actions, it is easy to fix in the settings
. And here you can see a list of all possible hotkeys for NetBeans.As to the features that are hidden behind the hot keys, and to which, in principle, you will not get but by exporting current keyboard shortcuts to HTML. Filter the list of keys for the word HTML, highlight the desired function and assign it its combination.
After pressing Alt+Shift+E (or whatever you put in) — HTML-file is generated, which has a list of all available functions and shortcuts to them, separated by profiles (NetBeans, Eclipse, Idea, etc). This file will be located in the folder with NetBeans settings.
In my Ubuntu the file path, is for example like this: /home/{user}/.netbeans/7.1/config/shortcuts.html
Bag of goodies
If you put the cursor on the word function
then all return
points will be highlight. And IDE correctly ignored return
from an anonymous function.
Ctrl+Shift+1 — highlights the currently open file in the project tree. And Ctrl+Shift+2 and Ctrl+Shift+3 does the same in the file tree and favorites, respectively.
Navigating through the open tabs and pressing the Ctrl+Tab the full path to the file in displayed in the left corner.
Annotations from the current VCS for a file:
. It’s convenient to watch, when and who edited every line of code.If run from a console:
*/netbeans/bin/netbeans path/to/file.php:15
then a file passed by the argument is opened in NetBeans on the 15th line.
Starting with the version NetBeans 7.1 they added a few more pleasant little things such as «rectangular» code selection and scaling code in the editor (holding Ctrl+ mouse wheel).
Handy when you need to look at the code from the «bird's-eye» perspective
or during presentations if there is a need to bring IDE to the big screen.
Woohoo!
IMHO, it’s the most powerful and versatile function of NetBeans. It allows you to automate most of the routine about coding.
When I started to write an article, I thought that right this part would be the most extensive. But in the process of work I found good materials that thoroughly describe all that is needed. I strongly advise to carefully review the materials and obligatory try to apply them in practice, taking into account the specifics of your project. I am confident that you’ll leave satisfied with the result.
NetBeans code templates
Some netbeans code templates are available in NetBeans out of the box. Let's look at one of them.
For example we have a line of code:
$e = $this->getEvent();
Type vdoc over a line, press Tab, and see the result:
/* @var $e MvcEvent */ $e = $this->getEvent();
The variable name and its type was picked up automatically. Isn’t it great?
And here is the «code» of the work piece (slightly formatted it for clarity):
/* @var $$${VARIABLE variableFromNextAssignmentName default="variable"} ${VAR_TYPE variableFromNextAssignmentType default="ClassName"} */
All the fine points are described in details and with screenshots in the article on the IDE site.
NetBeans macros
• The wonderful things that complement code templates in terms of automation, and allow you to realize all those little «spices» in the IDE, what is so missing for comfortable operation — netbeans macros.
Research on this topic from Alexander Makarov.
And a complete list of macro commands from the official site.
A wider range of css-macros for Netbeans.
Useful links
The official blog for PHP-functional for NetBeans:
The greatest amount of information on the IDE, as strange as it may sound, is placed on the netbeans.org site. But the structure there is so complicated that even with Google search it’s hard to find needed things. So I decided to select the most useful and relevant links to the docks and instructions for use separately.
Creating a project, work with code
Setting PHP-project (ru)
IDE NetBeans environment for JavaScript (ru)
IDE NetBeans environment for PHP (ru)
Testing and debugging source code
Testing with PHPUnit and Selenium (ru)
Detailed instructions for configuring XDebug (en)
Debugging source code PHP (ru)
And more detailed version in English
Screencast on using the code debugger in NetBeans (en)
Databases
Connecting to the MySQL database (ru)
Version Control Systems
Extensional guide for Subversion (en)
Git User Guide (ru)
The article refers to the NetBeans 7.0, where support for Git is implemented via a plugin.
User Guide on Git (en)
The English version describes how to use the native implementation of Git for NetBeans 7.1.
Deployment
Deploying a PHP application on a remote Web server by using the IDE NetBeans through S (FTP) (ru)
Screencasts
Declaring Variables in Comments and Associated Code Completion Features (en)