Vim logo vim online Vim Book Ad

basic Tip #317: Mozilla Vim Keybindings

 tip karma   Rating 70/25, Viewed by 1656 

created:   August 21, 2002 21:23      complexity:   basic
author:   Matthew J. Stott      as of Vim:   5.7

If you use VIM you like the h, j, k, and l movement keys.  I found myself annoyed at not having these movement keys available when browsing web pages.  Moving to the arrow keys on a laptop is annoying to just scroll the page.  

Locate your mozilla/res/builtin directory (varies by platform). You could search for htmlBindings.xml to find it. (ie. locate htmlBindings.xml.  

On Mac OS X it's inside the Mozilla application bundle.  /Applications/Mozilla/Mozilla.app/Contents/MacOS/res/builtin.

Create a new XML file called userHTMLBindings.xml, making it executable for all users and making sure the CRLF format is the same as htmlBindings.xml.  i.e. on Mac OS X most files use \r but Vim writes \n instead. You can either save the file with Vim as a Mac formatted file or use tr '\n' '\r' < input.xml > output.xml to convert the file.

Place the following XML into the userHTMLBindings.xml file.

<?xml version="1.0"?>

<bindings id="htmlBindings"
   xmlns="http://www.mozilla.org/xbl";
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">;

  <binding id="browserUser">
    <handlers>
      <handler event="keypress" key="h" command="cmd_scrollLeft"/>
      <handler event="keypress" key="j" command="cmd_scrollLineDown"/>
      <handler event="keypress" key="k" command="cmd_scrollLineUp"/>
      <handler event="keypress" key="l" command="cmd_scrollRight"/>
    </handlers>
  </binding>
    </bindings>


There are many more bindings one could configure to get Vim like keybindings.  You can read http://www.mozilla.org/unix/customizing.html#keys for more information.

PS.  I love the keymaster/gatekeeper xul reference in the xul URL above.  It's from the original GhostBusters movie.  ;-)




  

 rate this tip  Life Changing Helpful Unfulfilling 

<<Using /pattern/ search in a script | Extended Bracket and Parenthesis + extras for perl >>

Additional Notes

Anonymous, September 7, 2002 19:53
I found this didn't work in userHTMLBindings.xml, but adding relevant lines in htmlBindings.xml works great - thank you, this is one of those things I've always wanted!
Mohit Kalra, September 8, 2002 1:35
This comment is not exactly related to vim.  Anyways, checkout
http://labs.google.com/keys/index.html
Google for the keyboard aficionados.
-mohit
Anonymous, September 17, 2002 22:45
I admit it's a bit tricky to get this working.  Double-check your file format (CRLF, LF, CR) for the platform you are on.
Also check that you put the file in the right path for your OS.  I've gotten this to work on Linux, Mac OS X, and Windows equally well.  In some cases (*nix based environments) I think the files may need to be executable as well.  (in other words, where the other binding files were executable, I made the user binding executable as well).  

Good Luck
Anonymous, September 17, 2002 22:48
Didn't know about the Google Keys, that's pretty slick.  
[email protected], September 29, 2002 9:17
Maybe the _greatest_ tip I found here! Thank you!
It is a real live saver for me as I have been used to using lynx for years and I always used the vi motion in lynx.
I don't use Mozilla but Netscape 7. However, it worked all well for me (under Linux mdk 8.2)
Absolutely fabulous would be to be able to mimic all lynx keystrokes:
e.g.
"/" to search for a word (crtl-F in Netscape 7)
"g" to open a new URL
"v" to open the bookmarks page (alt-B in Netscape 7)
"a" to add a bookmark (crtl-D in Netscape 7)
etc.
I couldn't figure out how to do it yet.
Any idea?
Anonymous, October 15, 2002 9:45
Probably not, at least not without hacking the Mozilla source.  Most of what you listed would include a corded keypress.  i.e. ALT+Key, CTRL+Key.  All the Mozilla docs state for legal commands would be mostly navigation keystrokes like pageup/down, etc.  Also some editing and clipboard stuff.  See the link in the Tip for the Mozilla.org documentation.  Of course the modifier keys (CTRL+ALT, etc.) are customizable as it is done for each platform.  i.e. Mac's have a CMD key (Apple Key) that is used instead of CTRL.  A Mac has CTRL, Option(ALT), and Command(apple logo).  Sun has a CTRL, ALT, and a Meta key.  It may still be somewhat possible, you would have to replace the modifier key cording with a single key press.  However, this may produce undesirable effects that could impact normal Mozilla operation, etc.

Netscape 7 is really Mozilla under the hood.  Netscape took Mozilla as the base and added some stuff that isn't open source.  i.e. AIM client and some other things.  I find Netscape 7 to be bloated and full of useless fluff, but that's my opinion.  

Gecko is the rendering engine under the Mozilla hood.  XUL is a way to create a browser interface and can be heavily skinned.  XUL is literally rendered by Gecko.  So your widgets are all drawn by the render engine.  Neat concept but it can get a bit bloated (it's gotten much better with the 1.x releases).  There are many projects that take Gecko and wrap it up in a particular widget kit so it doesn't use XUL for the interface.  This eliminates the skinning but it makes for a lighter smaller non-cross platform browser, which apparently many people want badly.  Gnome, KDE, Win32, Cocoa/Aqua, etc., etc., etc.  They seem to want a native widget kit that matches their platform better.

Ultimately, I would want a lightweight browser that is really fast and good at one thing, rendering pages and loading plugins.  I could care less about email, chat, etc.  I have other programs for that stuff.  


If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo