Speed Up Development: NetBeans Code Templates, AutoHotKey, and Ditto

Share this article

Writing an application in PHP or any other language is both a rewarding and sometimes challenging endeavor. It’s also a time consuming process depending on the complexity of the project you’re working on. Some IDEs have built in tools or plugins that aim to speed up the programming process. There are also other helpful pieces of software such as libraries, code snippets, and third party applications. In this article I’ll show you how I use a feature built into NetBeans along with two other applications to increase my productivity when programming on Windows. These tips and techniques offer a different way of thinking about things which should be helpful to any developer, regardless of his skill level. I’m working with the NetBeans IDE for the purposes of this article. If you don’t already have it installed, you’ll need to make sure the Java JDK is installed first since it is a requirement for NetBeans. You can download the latest JDK from Oracle. Once the JDK is installed, you can download NetBeans from target=”_blank”>netbeans.org/downloads. There are several versions of NetBeans available; I downloaded the All bundle because in addition to PHP I also do some C and Java development. If you only need PHP support, then feel free to install the PHP bundle instead.

NetBeans’ Code Templates

Go ahead and start NetBeans and create a new project; a dummy project will be sufficient for our purposes right now. Select File > New Project from the main menu bar, and in the New Project dialog select PHP Application and click Next. Since you are only creating a dummy project, you can click Finish on the next screen. NetBeans creates the new project and opens the new index.php file for you to edit. Code Templates is NetBeans’ code snippets functionality. Using templates allows you to write an abbreviation for a common piece of code and then press a trigger key to replace the abbreviation with a code snippet. Let’s try one of the templates that are already defined… In index.php which was opened after creating the new project, place the cursor after the comment in the PHP block and press Enter to insert a new line. Then type the word if and, instead of pressing the space bar, press the Tab key. NetBeans will add the beginnings of an if statement to your script. Now let’s create a new code snippet. Select Tools > Options from the main menu, and click on the Editor icon at the top of the Options window. Choose the Code Templates tab and then select HTML from the Language drop down. Click on the New button, type pre in the Abbreviation field, and click OK. In the Expanded Text field, type the following:
<?php print_r(${cursor}); ?>
I’ve chosen this as a simple example because it’s a common method to view the contents of arrays and objects in PHP. NetBeans is code aware, so because you created the snippet in the HTML templates it won’t work if you’re inside a PHP block. The ${cursor}
variable in the snippet tells NetBeans where to place the cursor after the trigger key is pressed. After you’ve typed the code, click OK and test it out.


Now that you know how to define Code Templates in NetBeans, let’s move on to another piece of helpful software– a program called AutoHotKey. AutoHotKey is a scripting language to automate tasks on Windows. You can download it from www.autohotkey.com/download. Once AutoHotKey is installed, right click on the desktop and select New > AutoHotKey script and name the file anything you like. Open the AHK file in a text editor like notepad, and type the following:
Send pre{tab}
The pound sign tells AutoHotKey to listen for the Windows key, the caret signifies the CTRL key, and P is just the P key. The two colons afterwards tell AutoHotKey this is a batch of commands. The next line sends the keystrokes p, r, e, and a Tab to whichever window is active at the moment. Those keystrokes also match your Code Template abbreviation and the trigger Key in NetBeans. Return tells AutoHotKey to stop processing lines and start listening for other keys. Save the file, then right-click on the AHK file and select Run script. Go back to NetBeans and delete the previous pre block you inserted using Code Templates. Now on your keyboard press CTRL + WIN + P and the pre block should be inserted and the cursor placed in the correct location. AutoHotKey has a simple but effective syntax for scripting Windows. You can read more about its hotkey and see more sample scripts at www.autohotkey.com/docs/Hotkeys.htm.


The final piece of software I’d like to bring to your attention is Ditto. Ditto is a clipboard manager, and is one of the better ones I’ve tried as it is unobtrusive and has a small memory footprint. You can download it from ditto-cp.sourceforge.net
. Once Ditto is downloaded, extract the contents of the archive file to any location of your choosing. Open the folder and double-click on the Ditto.exe file. This runs Ditto and places it in the System Tray. Right click on the Ditto icon and click on Options. I set a couple of options but most of the defaults have proven to be sufficient in the time I’ve been using it. For example, Ditto defaults to a storage size of 500 items which is plenty in my opinion, but you can change this number to suit your needs. The options I have changed however are to start Ditto on system startup and its shortcut key to CTRL + SHIFT + V. This allows me to use Ditto by pressing one additional key to paste. Let’s operate under the assumption you’ve copied and pasted several variable names for arrays, and now you want to see the contents of one of them. In NetBeans, press CTRL + WIN + P to insert your pre block, and then press CTRL + SHIFT + V until the variable name you wanted to use is shown. You’ve cut down a lot of your keystrokes and have managed to keep your hands in similar positions on the keyboard! Ditto allows you to sync your clipboards across multiple computers, which is great if you can forward ports with your router, adjust your firewall settings, etc. Unfortunately I don’t have access the port forwarding settings in the router at the office. To get around this limitation, I copied the ditto.db from the Ditto folder and placed it in a Ditto directory in my Dropbox account. Then I change the database path in Ditto’s options to point to the Dropbox folder. I just have to remember to close Ditto before I leave my office computer and the database stays synced between my other computers. I also make use of Dropbox to store my AutoHotKey scripts.


In this article I’ve shown you how I use NetBeans’ Code Templates with AutoHotKey and Ditto to boost my productivity when programming. If you weren’t familiar with these programs before, I hope you find them useful and helpful. If you have any productivity tips you’d like to share, feel free to do so in the comments section below. Image via Gunnar Pippel / Shutterstock

Frequently Asked Questions (FAQs) about Code Templates, AutoHotkey, and Ditto

What are the benefits of using code templates in AutoHotkey and Ditto?

Code templates in AutoHotkey and Ditto can significantly improve your productivity. They allow you to automate repetitive tasks, reducing the time and effort required to perform them. For instance, you can create a template for a piece of code that you frequently use, and then simply insert it whenever needed, instead of typing it out each time. This not only saves time but also minimizes the risk of errors.

How can I create my own code templates in AutoHotkey?

Creating your own code templates in AutoHotkey is straightforward. You can start by identifying the pieces of code that you frequently use. Then, you can use the AutoHotkey scripting language to automate these tasks. The scripting language is easy to learn and use, even for beginners. You can find numerous tutorials and resources online to help you get started.

Can I use Ditto with other programming languages besides AutoHotkey?

Yes, Ditto is a universal clipboard manager that can be used with any programming language. It stores all the items that you copy to the clipboard, allowing you to access and use them later. This can be particularly useful when you’re working with multiple pieces of code in different programming languages.

How does Ditto compare to other clipboard managers?

Ditto stands out for its simplicity and efficiency. It’s lightweight, easy to use, and offers a range of features that can enhance your productivity. For instance, it allows you to search through your clipboard history, assign hotkeys to specific items, and even synchronize your clipboard across multiple devices.

What are some of the best practices for using AutoHotkey and Ditto?

When using AutoHotkey and Ditto, it’s important to keep your scripts and templates organized. This will make it easier for you to find and use them when needed. You should also regularly update your scripts and templates to ensure they’re optimized for your current tasks. Additionally, make sure to use the search and hotkey features in Ditto to quickly access your clipboard items.

Are there any limitations or drawbacks to using AutoHotkey and Ditto?

While AutoHotkey and Ditto offer many benefits, they do have some limitations. For instance, AutoHotkey’s scripting language may not be as powerful or flexible as other programming languages. Similarly, Ditto may not offer as many features as some other clipboard managers. However, for most users, these limitations are outweighed by the benefits.

How can I get started with AutoHotkey and Ditto?

To get started with AutoHotkey and Ditto, you can download and install them from their respective websites. Once installed, you can start creating your own scripts and templates in AutoHotkey, and use Ditto to manage your clipboard items. There are numerous tutorials and resources available online to help you learn how to use these tools effectively.

Can I use AutoHotkey and Ditto on different operating systems?

AutoHotkey is designed for Windows, and may not work on other operating systems without additional software. On the other hand, Ditto is a Windows-only application. However, there are similar tools available for other operating systems, which offer comparable functionality.

Are AutoHotkey and Ditto suitable for beginners?

Yes, both AutoHotkey and Ditto are suitable for beginners. They’re easy to use and offer a range of features that can enhance your productivity, even if you’re new to programming or coding. Plus, there are numerous tutorials and resources available online to help you get started.

Are AutoHotkey and Ditto free to use?

Yes, both AutoHotkey and Ditto are free to use. They’re open-source software, which means you can download, use, and even modify them without any cost. However, if you find these tools useful, consider donating to the developers to support their work.

Chris RobertsChris Roberts
View Author

Chris Roberts is a web developer for heels.com in addition to being a freelance developer. When he's not writing code he can be found trying to become a better designer, especially in typography-related topics, or playing the guitar.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form