Firefox: Emacs-style keyboard shortcuts, as well as loading clipboard contents with the click of a middle mouse button

I want to share with the habro-community two recipes for “preparing” Firefox for a more pleasant and convenient use in the daily life of Unixoid.

It will be about the version of Firefox under FreeBSD. But everything described below is quite applicable to the version for Linux. For Windows, everything is not so simple and can be solved in other ways.

I will describe the method of "embedding" Emacs style keyboard shortcuts in Firefox, as well as how to make Firefox load any clipboard content on the mouse middleclick, not just the one that looks like a link (has the http: // prefix , etc.) .

If the topic is interesting, please under the cat.

So. Each of us, who for various reasons uses the shell (in particular, bash), is probably familiar with Emacs-style keybindings. For instance:
Ctrl - a: go to the beginning of the line
Ctrl - e: go to the end of the line
Ctrl - u: delete to the beginning of the line
Ctrl - k: delete to the end of the line

I'm so used to using these keyboard shortcuts that I often try to inertia use them in other programs. In particular, in Firefox. However, this leads to unexpected results. For example, the combination “Ctrl - w”, instead of deleting the word in front of the cursor, simply closes the current tab.

Once upon a time I was tired of this state of affairs and I used the method found in the vastness of MozillaZine . And since then I use this solution with every update of Firefox. Below I will describe the sequence of actions.

First we need installed Firefox. On FreeBSD, it can be installed from the ports collection ( ports / www / firefox ). Next, you need to take the toolkit.jar file . By default, on FreeBSD, it is installed in the / usr / local / lib / firefox / chrome / directory . Then you need to unpack it. You can do this using the jar utility from the JDK delivery, or the fastjar utility ( ports / archivers / fastjar ), or the usual unzip : The

mkdir /tmp/firefox/ && cd /tmp/firefox/ && cp /usr/local/lib/firefox/chrome/toolkit.jar /tmp/firefox/ && fastjar -xf toolkit.jar

contents of the archive will be unpacked into the current directory. Next, add the following to the file content / global / platformHTMLBindings.xml :

1) in the section section

2) to the section sections and

After that, we pack the archive back: " fastjar -cf toolkit.jar */" (or using " zip -r"). And move it to the source directory:

mv toolkit.jar /usr/local/lib/firefox/chrome/toolkit.jar

For this you will need root privileges. Also, of course, the toolkit.jar file must first be backed up.
We restart Firefox and enjoy the presence of Emacs-style keyboard shortcuts in all text fields, including the address bar of the browser.
In order to avoid digging into the contents of the content / global / platformHTMLBindings.xml file each time a new version of Firefox is released , I wrapped these changes in a patch .

Move on. Starting from the 4th version of Firefox, I came across the fact that by clicking the middle mouse button the browser no longer tries to download the link from the clipboard if this link does not have the corresponding prefix ( http: // , etc.). That is, if I, say, from the web server’s log, copy the name of the virtual host to look at its website in the browser, then instead of the usual middle click in the browser window, I have to put the cursor in the address bar, paste the content there clipboard and press enter. To put it mildly, this innovation drove me so disheartened that it made me turn again to search for a solution on the Web. And a solution was found. It involves the same procedure as the method described above. Only the files we will edit will be different. Take the filebrowser.jar from the directory / usr / local / lib / firefox / chrome / , backup and unpack it. Further in the file content / browser / browser.js we find this block:

  try {
  } catch (ex) {
    // Not a valid URI.

and replace it with this one:

  var URIFixup = Components.classes[";1"]
  url = URIFixup.createFixupURI(url, 1).spec;

Save, pack back and move the newly created browser.jar back to the / usr / local / lib / firefox / chrome / directory . We reboot the browser, make sure that the contentLoadURL option is true in about: config and enjoy the result: now, when you click the middle mouse button, the browser will try to load any content from the clipboard, not just the one that it considers the link. As for the previous method, you can also use the appropriate patch . Both methods have been used by me for a long time and have already been tested for performance in the recently released FF 10.0.

One minus to this approach: patches must be applied after every Firefox update.

I hope this article will be useful and will bring someone even more satisfaction and enjoyment from working in your favorite browser.

The following materials were used in the article:
1. Emacs Keybindings - Firefox (MozillaZine).
2. Firefox 4: Fixing middlemouse.content load, and hacking jars (

Also popular now: