Products Docs & Support Community

A new old keybinding for NetBeans IDE

Why vi?


"I'm back to 100% productivity again!" Rob cheers on the openide-dev mailing list. And his fellow community member Antonio asks "Where can I make a donation to this project?"

The project they are so excited about is the new jVi plugin for NetBeans IDE 5.5. The developer looking forward to (hopefully) incoming donations is Ernie Rael. The preview NBM he just released is an editor module enabling you to use vi editor commands in NetBeans IDE.

If you now ask "Why would anybody want vi keybindings?" then, sorry, this plugin is not for you. The target group is developers who have internalized vi shortcuts to a degree that it significantly speeds up their coding.

Has it ever occured to you how much time it takes to click and select text with the mouse? Vi shortcuts let you jump to any spot in your code, copy from and paste to several clipboards, search and replace regular expression patterns, and swap, delete or replace characters, words, lines or paragraphs -- all with a few keystrokes.

Combine your vi skills with an IDE like NetBeans and you get a true killer app. Yes, the learning curve for vi is steep. But we are not suggesting you should start learning vi. We are suggesting that developers who already know vi should be enabled to continue using it. Just like developers who are used to Emacs or Eclipse have the option of leveraging their existing knowledge of those keybindings.

The current release of NetBeans IDE (5.5) already comes with the default NetBeans keybindings as well as Emacs and Eclipse keybindings. There used to be vim 6.2 keybindings provided by the External Editor team. But that was around the time of NetBeans 3.5, over three years ago. Now that Ernie ventured out to revitalize this famous set of keybindings, the response is as enthusiastic as for the first implemenatation.

Tips:


To give you a picture, here are a few examples of vim commands I use a lot:

  • 1G and G (jump to beginning or end of file)
  • 4dd and 4yy (delete or copy 4 lines)
  • :.,+5s/foo/bar/g (between here and the next 5 lines, replace all 'foo's with 'bar's)
  • xp, dwwp and ddp (swap two letters, two words, two lines)
  • fx and tx (move the cursor onto, or before, the next occurence of letter x)
  • Type reg: to peek at the content of your 26 clipboards. Type "ayw to yank a word into register a, or "zyy to yank a line into register z. Paste the content of register a with "aP, and z with "zP.

Note that installing jvi does not block normal commands like ctrl-c and ctrl-v. Code completion still works as expected in all kinds of files that I tested (java, html). You can also still use the mouse to position the cursor and select text.

Install the Module


The module consists of two NBMs, the first is the jVi implementation, and the second one, nbVi, handles NetBeans integration. "jVi is designed to be quickly and easily integrated into various Java-based desktop apps," explains Ernie, "from IDE's to mail-news readers."

Follow these steps to try the module out for yourself.

  1. First make sure you have Java 5 or better, and NetBeans IDE 5.5 installed.
  2. Download the jvi zip file from sourceforce and extract it.
  3. In the IDE, save all your open projects's changes. Select Update Center from the tools menu and check Install Manually Downloaded Modules, then click Next.
  4. In the installer wizard, add the two .nbm files that you find in the "nbvi-0.8.0x8" directory
  5. Complete the wizard. Accept the certificate and check the "Include" checkbox to install it.
  6. Restart NetBeans when prompted to do so.

You can tell the installation was successful when you see the cursor turn into a black box in the Editor. When you now type a colon you should see the vi input line appear at the bottom of the page. Press escape to return to vim's normal command mode.

Configuration


You probably will want to customize your vim keybindings. Select Options from the Tools menu and click the Advanced Options button. There you'll find a new "Editing/jvi Options and Configuration" node. For some reason, a couple of options shown were missing for me, so I couldn't try them yet, but the screenshots look promising.

If the vim bug has bitten you, make sure to read the extensive documentation provided by Ernie Rael on his project homepage. Open the file "nbvi-0.8.0x8/jvi-docs/index.html" in your webbrowser and see all the features it has to offer.

Issues:


After installing the jvi keybindings 0.8.0, you'll soon come across one major disadvantage. As of now there is no user-friendly way to switch between NetBeans keybindings and the jvi keybindings. The current pre-release still requires you to deactivate the plugin completely to get back to the default. In order to do that, go to the Module Manager in the Tools menu and deselect the jvi module.

Release 0.8.0 also had a few bugs that threw errors when I tried to search strings with the / command, or when I searched for regular expression patterns using the :s/// syntax. If you encounter similar bugs in everyday use, or notice missing features that are a must-have — send feedback to Ernie. As usual, have a look at the known bugs before contacting the author or filing a bug report.

Still it is very promising, keep up the good work!


PS: This article was written with jvi. :-)

Related Pages


  • jVi's Homepage on SourceForge
  • jvi 0.8.0 - known bugs and issues
  • Antonio's Blog: NetBeans vi editor module!!
  • Masaki Katakai's blog
  • Viex -- another SourceForge project for vi integration (in progress)