2006-02-19

Who is this tutorial for?

  • jEdit lovers who have yet to discover the power of abbreviations and the SuperAbbervs plugin.
  • Those new to jEdit who want to give it some killer functionality
  • People looking for documentation or a manual on how the hell to use Abbreviations and SuperAbbrevs
  • Those looking for yet another reason to switch to jEdit, one of my very favorite programs.
  • Those looking for Textmate-like functionality in another editor
  • People coding in HTML, XML, Ruby (on Rails) and any other language. I will be using HTML and RoR for my examples since that’s what I code my sites with, but you can apply this stuff to any language.

What are abbreviations and SuperAbbrevs?


One of the cool things you’ll see in Ruby on Rails videos when people are using Textmate is that someone will type something like:

linkto

and it will output:

<%= link_to '', :action => "" %>

Or maybe you just wanted to be able to type table code really fast when you’re doing HTML:

table

output:

<table>
<tr>
<td>

</td>
</tr>
</table>

This is an abbreviation. It takes a simple text input and makes you more efficient by giving you a code output at the touch of a key that would have been much more laborious to do all by hand. Basicially it just saves you a ton of typing. So whether it’s a huge statement you want to output or a small set of HTML tags you can save yourself a lot of typing with this little thing. Isn’t that convenient? And you probably thought you had to have Textmate to take advantage of such an awesome feature (I believe they call them “snippets”). That is most certainly not the case.

Examples of where you might use it

So. In what situations can you use jEdit’s awesome abbreviations or SuperAbbrevs plugin? Here are a few examples:

Text input Code Output
table <table><tr><td></td></tr></table>
pe <%= %>
trtd <tr><td></td></tr>

These are just some of the things you can do with them. As you can see you can use them for a lot or a little code. Personally I hate going very far away from the home row on my keyboard at all (which is why I also use dvorak), so even the pe abbreviation to save me from having to type <%= %> is a real life saver; it’s just such a pain in the ass to find that % key sometimes.

The HOW-TO

I’m just going to show you how to use SuperAbbrevs because I believe they are superior to Abbreviations built into jEdit for how most people will want to use them. If you want to play around with Abbreviations they work similarly and can be found in Global Options in jEdit.

On with the show!

First you need to get jEdit. You should either have it already or get it right now.

Installing SuperAbbrevs

  1. Go to Plugins -> Plugin Manager.
  2. Click on the Install tab.
  3. Find and click the checkbox for SuperAbbrevs
  4. Click Install at the bottom lefthand corner
  5. Close that dialog

Setting up an Abberviations Shortcut

  1. Go to in the file menu Utilities -> Global Options -> Shortcuts
  2. Click on the dropdown box and select Plugin: SuperAbbrevs
  3. Double click on either the Primary or Alternate shortcut box. It should bring up a dialog that says Specify Shortcut

  4. Press the keys CTRL and Enter similtaneously on your keyboard. This sets up a key combination to expand your text input abbreviation into awesome blocks of code.

Making an abbreviation

  1. Go to Plugins -> Plugin Options -> SuperAbbrevs
  2. At the top click on the dropdown for Abbrev set and select global
  3. Click the little + (plus) icon at the bottom left. This will open a box that should say Edit Abbreviation.
  4. The box labeled Abbreviation is where you type what text input you want to use. For this example we’ll be typing table in it.
  5. The box that says Template text is where you enter the code to help you display your abbreviation. In this box we’ll type:

    <table>
    <tr>
    <td>$1</td>$2
    </tr>
    </table>$end

    Click OK

  6. This tells jEdit that we want to be able to type table and then hit ctrl+enter on the keyboard and it will output a table for us. The numbers with the $signs in front of them represent spots where you want to be able to tab to.. So in other words you can press tab and it will go to each one of the numbers and you can type whatever you want in them. The $end variable represents the end of your expanded code. If you type anything at this point you will exit the abbreviation and go back to normal editing.. so basically you just can’t tab/shift+tab through the abbreviation anymore.

Using your abbreviation

  1. If you haven’t already press OK to exit the Plugin Options dialog
  2. Open a new buffer or some other html document that you can type in
  3. Type table somewhere in your document and then press CTRL+Enter on your keyboard. You should see this:
    <table>
    <tr>
    <td></td>
    </tr>
    </table>

    If you don’t, then go through the steps again and make sure you have everything done the way I show it in the screen shots.

  4. Your caret should be located between the two td tags. Type hi.
  5. Press Tab on your keyboard. It should go to the outside of the last td tag. Press enter and type:

    <td>hi again</td>
  6. Press tab a few more times. It should cycle through all your different edit areas of your abbreviation.
  7. Stop tabbing sometime when it gets to the end of the table tag. Type something. Now press tab. You’ve just exited your abbrevation!

More Examples

  1. Here’s a PHP example. I use fun for the abbrev and the following for the expansion:

    function $1(\$$2)
    {
    $3
    }$end

    This is an example of how you can escape the $ character. In this example you actually don’t need to.. the only time you need it is if you put a number or the keyword end after the $ sign. But it won’t hurt your abbrev in this example either.

  2. Try this in a superabbrev; I use the abbrev img the expansion is:

    <img src="$2" alt="$1" />$end

    This shows that you can put things out of order.. maybe it will remind you to actually type something in that alt tag.
  3. Often in Rails you’ll want to type out a link_to tag in your views. Maybe you don’t always remember what to type where. In this example I use linkto as my abbrev and the following as my expansion:

    <%= link_to '${1:name of your link}', :action => '${2:name of your action here}' %>$end

    Type linkto in your document and then press ctrl+enter (or whatever your expansion key combo is). It will expand your abbreviation and have example text in place so that you can remember what goes in those.

  4. Try writing out an superabbrev and putting the variables ($1, $2, $3..) in multiple times. So like:

    <img src="$2" alt="$1" title="$1" />$end

    You should see whatever you type in the alt ($1) attribute is the same in the title attribute. By the way - don’t ever do this as a real abbreviation. This is a misuse of the alt and title attributes and anyone caught using this in a real production scenario should be shot. This is just an example.

Nice work. If you kept up with me that whole way, go you. If you have questions or comments.. please comment.

Notes

  1. You may not want to set Abbreviations for global. You can select them to only work for certain languages if you want. This way you can have the abbreviation “b” make a bold tag in HTML and then have it do something entirely different in RoR like write out “before_create” or something. That’s not a very good example of what you’d really use it for, but you get the picture.
  2. There’s more you can do with abbreviations and stuff. Play around with it.. and look at documentation (Help -> jEdit Help -> Search. Then search for “abbreviations” or “superabbrevs”).

54 Responses to “jEdit Tutorial: A How-To on Abbreviations in Superabbrevs for HTML, Ruby on Rails and more”

  1. firebird Says:

    very good!

  2. Joshua Says:

    Thanks for the tip!
    I’ve been looking for a solution like this.
    I’m reluctant to try an Java based IDE, but this just might be the deciding factor.
    Thanks!

  3. Sune Simonsen Says:

    The beta version of SuperAbbrevs can be found here.
    http://community.jedit.org/?q=node/view/2761
    http://community.jedit.org/?q=node/view/2762

  4. Scott Becker Says:

    Should’ve posted this here a while back - inspired by this tutorial and a couple others, I created a collection of jEdit snippets for Rails:

    http://synthesis.sbecker.net/articles/2006/03/20/jedit-snippets-for-ruby-on-rails

  5. TheElder Says:

    HECK 2 the YEAH! GREAT POST DUDE!

  6. Jonathan Aquino Says:

    Or use AutoHotKey and get superabbrevs functionality across all Windows apps, not just jEdit.

    Actually I just used it to fill in the blog info above–I typed in ja` for my name, mail` for my email, and web` for my website.

  7. Kaleb Walton Says:

    Excellent resource! I’ve included a link to this in an article on jEdit and other RoR IDEs (jEdit being my personal fav). Thanks for explaining abbreviations in detail so people can easily understand it!

  8. KevinKleinfelter Says:

    If you find that tabbing between $ variables is broken (gives a Bean Shell error on an undefined method), you will find that Jedit 4.3pre6 will work with the beta SuperAbbrevs mentioned by Sune (http://community.jedit.org/?q=node/view/2762). The beta description only mentions 4.3pre3 and pre4, but it works with pre6. The non-beta version has problems with $ variable processing.

  9. Sune Simonsen Says:

    Hehe I didn’t even know about that, I will update the description.
    I am really busy at the moment so thats why nothing is happening to the plugin rigth now. But I try to get the time to release what I have for 4.2 before it’s too late :-)

  10. Developing Ruby on Windows or The Search for the holy Textmate Says:

    [...] dit mit dem SuperAbbrevs-Plugin und diversen anderen Plugins ist sicher eine gute Lösung. Hier das Tutorial dazu. [...]

  11. Sune Simonsen Says:

    There is a new beta version of SuperAbbrevs avialable from the links below.
    http://community.jedit.org/?q=node/view/2761
    http://community.jedit.org/?q=node/view/2762

  12. Alex Ezell Says:

    It seems to me that SuperAbbrevs no longer offers a shortcut to expand the abbreviation you just typed. Now it launches a dialog into which you type the abbreviation and the expansion is inserted at the cursor.

    This is a step backwards if there is no way to go back to the former functionality.

  13. Sune Simonsen Says:

    Hey Alex Ezell
    Write the abbreviation and press the TAB key, then the abbreviation should be expanded.

  14. DigitalHobbit » Blog Archive » Ruby Editors / IDEs Says:

    [...] , which simulate all the TextMate snippets and more. There’s also a good tutorial on setting up the SuperAbbrevs [...]

  15. Sune Simonsen Says:

    SuperAbbrevs beta 3 is out, this time the jarfile works for all version of jedit after 4.2.

    http://community.jedit.org/?q=node/view/2761

  16. Fernando Meyer’s WebLog » jEdit as TextMate equivalent for Windows based Ruby on Rails development Says:

    [...] for a number of reasons. jEdit Tutorial: A How-To on [...]

  17. tasa Says:

    Hi, do you still have the file with jEdit snippets for RoR from here (http://synthesis.sbecker.net/articles/2006/03/20/jedit-snippets-for-ruby-on-rails)?
    If you have i wuld thank you a bunch if you could send it to me, or put somewhere for downloading, as the original download appears to be down, and the blog appears to be forgotten.

    Thanks

    P.S. Actually, uploading it would be a better option, as I seen many who seek this file in vain.

  18. jedit and web development as a free alternative for textmate « me looking so small in this world Says:

    [...] 2006 for nothing. Have several bundles to use. Whew.. Cool. Then there’s this great tutorial [...]

  19. found it Says:

    Found a set of shortcuts at http://dovetailcomputing.com/blog/2006/09/18/using-jedit-for-ruby-on-rails/

  20. Sune Simonsen Says:

    SuperAbbrevs 0.23 has just been released to the plugin manager.

    Enjoy !

  21. Editores + Ruby on Rails + Linux Says:

    [...] s que usei para configurar:

    http://www.eadz.co.nz/blog/article/ruby-rails-jedit.html

    jEdit Tutorial

    Rad [...]

  22. hrax Says:

    hey dude. Nice tutorial. Im more interested in mixing “variables” of abbreviation. SuperAbbres can’t understand something like this: ${1:class=”${2:inner}”}, TextMate can and i really miss this option.
    Has anyone an idea how to make it work? thanks

  23. marekj | software testing » jEdit and Ruby and SuperAbbr plugin Says:

    [...] s pluging is impressive because it introduced a block of code and markers you can jump to. Here is a nice tutorial [...]

  24. Sune Simonsen Says:

    Hi hrax

    I’m Sorry but that feature is not in SuperAbbrevs right now, and it will be a while before I get around to implement it. There are so many other improvement and refinements I want to make first.

  25. Vinay Says:

    Hey thanks for the tips. Was really very helpful in understanding the jEdit. Keep up the good work.

  26. Robert Says:

    Can you wrap text in tags? Please email me if you can.

    Robert

  27. Sune Simonsen Says:

    Yes you can wrap text in tags. Use the following template:

    Select the text you want to wrap, and invoke the action
    Plugins -> SuperAbbrevs -> Show expansion dialog
    write the abbreviation for the template above and hit enter.
    The selection will now be wrapped in tags.

  28. Roy Says:

    Hi,
    I’m obviously missing something here. I’ve just started using jEdit 1.5.0_06 and when I tried to get SuperAbbrevs going - no luck. The boxes I get look somewhat different to those shown above, also it seems that SA is already installed as it comes up in the Plugin Options dropdown and shows Tab, Shift Tab and Show expansion dialog options.
    When I type “if” and hit Shift Tab, an Add Abbreviations dialog comes up and I can insert the extended code into page. But this is obviously not what people are talking about.

    Any help very welcome

  29. Gerald Redila Says:

    thanks for the help. setting up and workin gwith the plugin was grat. but i have a problem with assigning + keystroke to “Expand abbreviation” cause its not on the list when i selected plugin:SupperAbbrevs

    I only see three items there, namely: Tab, Shift+Tabl, and Show expansion dialog…

    I tried reinstalling the SUperAbbrev plugin but it didnt change a thing. WHat should i do?

  30. Sune Simonsen Says:

    Hi Roy & Gerald Redila,

    First to you Roy, the SuperAbbrevs plugin is only installed if you isntalled it. And the version of jEdit you mention does to my knowledge not exist. I think you eighter uses jEdit 4.2 or 4.3pre. The plugin works like this: You types an abbreviation in the text area and hit tab, if the abbreviation exist for the editing mode you are in the abbreviation will be expanded. When you hit the tab key again the first field will be selected. By using the tab key you can jump between the fields in the code template. Here is a demo of the plugin in action http://www.we-knowhow.dk/jedit/demo.html .

    Gerald Redila, the new version of the plugin uses the tab key to expand the abbreviation like explained above.

    Hope this clears things up a bit.

  31. Matt Gordon Says:

    For those of you who aren’t happy with using the Tab key to expand abbreviations in SuperAbbrevs, you can change the Tab _shortcut_ from the Tab key to something else. For example, I switched to the backtick:
    Tab: `
    Shift Tab: S+`

    I switched it because I have the Tab key set to indent lines (for emacs-like behavior) and SA was breaking it. I’d love it if the behavior of Tab was context sensitive but I couldn’t see any easy way to do it. Maybe a macro…

    Also, Sune, if you’re reading this, where is the definitive page for SA? The links above all appear to be broken. Thanks for the great plugin.

  32. phipster » Blog Archive » jEdit for Ruby on Rails Says:

    [...] 21; window. Also see the excellent tips on Eadz’s Ruby on Rails on jEdit page, and this howto on setting up [...]

  33. Sune Simonsen Says:

    Hi Matt Gordon

    There is no definitive page for SA, the links above are for beta version. The newest version is included with jedit in the plugin manager.

    Regards Sune Simonsen.

  34. Fabio Varesano Says:

    Thanks for this post!

  35. Jan Wikholm Says:

    Thanks!

    After using jEdit for 7 years now, it is nice to still learn something new. I had been using the regular abbreviations built in jEdit, but it was nice to find that there is such a plugin that makes those multi-part abbrs easy as pie.

    This will help me with xslt which is an insanely verbose language :)

    Cheers!

  36. Jonathan Says:

    Thanks for the great article again. It’s hard to go from Visual Studios to JEdit but I’m hoping this will be my editor of choice after a few weeks. I would like to say as a ‘newbie’ to Jedit, you need to go into options and select Plugin Manager and then download the mirrors and select a mirror before your plugin manager will function correctly. This is from a fresh install only I think. Thanks, Jonathan

  37. kwerle Says:

    Super useful - I was trying to find out how to have text in the areas to fill in, and here it is.

  38. Brian Says:

    Hey, thanks for the good writeup. However, when I go to Global Options -> Shortcuts, and pull down SuperAbbrevs from the pull down list, there is not an “Expand Abbreviation” command listed. Only “Show dialog window” and “Tab” are there.

    So, obviously I can’t set a command to expand the abbreviation. Any idea how to get it to show up for SuperAbbrevs?

  39. jessecrouch Says:

    Hey Brian -

    Yeah I see that too. Use “tab” which is the new way Sune is saying “Expand Abbreviation”.

  40. Brian Says:

    Unfortunately, no it doesn’t seem to change a thing. I have the abbreviation for ” Shortcuts, I even changed “tab” to be SHIFT+ENTER

    now when I type “$end

    I can get the normal built in abbreviations to work, just not the SuperAbbrev ones. Its like it isn’t even enabled, or isn’t running, or something. But it clearly shows in the plugins manager that its installed and checked.

  41. Brian Says:

    whoops… your blog totally stripped out all the code I had in there, probably doesn’t make any sense now.

  42. Sune Simonsen Says:

    Hi Brian,

    The tab-key should be wired to the Tab-action when you install SuperAbbrevs.
    Could you provide a little more details, then I’ve maybe be able to help you.

  43. Aki Says:

    Thanks! Great tutorial. I usually use Texteditor with my Mac to do coding, but sometimes I have to use a Windows machine(don’t ask me why), and It was just driving me crazy.

  44. ankraj Says:

    thank you.

  45. Best IDE/Editor for Ruby on Rails? - jesse crouch’s log » Blog Archive Says:

    [...] I’ve written a tutorial on how to get TextMate like functionality in jEdit. You’ll want to go through this is if you use jEdit for [...]

  46. harika cocuklar Says:

    thank you very much

  47. ersin Says:

    thanx for all this.

  48. John Says:

    Here’s a question.. I was having trouble because I wanted to expand an abbreviation within another abbreviation. Say, type “h3″ to get “|” and then after typing some text expand “i” () within the h3. You can’t do this because the shortcut keys aren’t reactivated until you exit the abbreviation.

    What I figured out is that when you have only a single variable in an abbreviation, such as “$1$end” it’s really better not to use the variable. If the abbreviation is instead “$end” then you exit the abbreviation immediately after it is expanded. And then you can enter and expand another abbreviation from within the first one.

  49. sickill Says:

    Nice tips! If you are intereseted in making your JEdit a little prettier I’ve written converter from Textmate’s colour scheme format to JEdit’s format. Please check my post at http://sickill.net/blog/2009/01/20/textmate-to-jedit-colour-theme-converter.html . You can grab there the converter and/or already converted 16 schemes.

  50. karatedog Says:

    Regarding to the “Notes”, I would like to add a few abbreviation to a new “mode”, namely .erb or .html.erb. How do I create that mode?
    If I create a file with the extension, say .uuu then all abbreviations I create in this file go to Global.
    So I actually miss the Create and Delete mode function from the SuperAbbrevs plugin (I know, I know, I’m greedy :-)

  51. jessecrouch Says:

    Probably have to create this new mode in jedit’s modes itself, not superabbrevs.

    I usually just put all my abbrevs in global. I mainly only work in html/js/ruby/java/css though.

  52. karatedog Says:

    Thanks for the fast answer!

  53. Ignacio De La Madrid Says:

    Great post man! I really like Textmate-like editors such as JEdit and Gedit in Linux. Programmer editors when you know how to use them , are faaaar better than IDE’s. Thx.

  54. Udo Güngerich Says:

    Thanks for this howto!

    I could not find any documentation what syntax the variables should follow. Only your post made me try $1 and ${2:name_var} styles (like in eclipse) and it worked.

    This (in combination with the GroovyScriptingPlugin) is one of the last bricks for building the bridge from eclipse to jedit.

    Regards, Udo

Leave a Reply


I've left the country and this site is just an archive! Check out my trip blog!