Wikia

Vim Tips Wiki

Vim key bindings for web browsers

Talk0
1,613pages on
this wiki
Revision as of 18:27, June 16, 2013 by 67.244.81.209 (Talk)

Tip 317 Printable Monobook Previous Next

created 2002 · complexity basic · author Matthew J. Stott · version 6.0


Vim users find the h, j, k, l keys useful for navigation. This tip shows some techniques for using similar key bindings in the Mozilla Firefox web browser.

Extensions

Pentadactyl

Pentadactyl is a free browser add-on for Firefox, designed to make browsing more efficient and especially more keyboard accessible. Largely inspired by the Vim text editor, the appearance and finger feel of Pentadactyl should be familiar to Vim users. Additional web-specific features, such as our ‘Hint’ mode, command interface, and key bindings to automatically follow back and forward links, make it easy to navigate without touching the mouse and give Pentadactyl a habit forming nature of its own.

Vimperator

Vimperator is a free and supported addon for Firefox, and is the best way to configure Firefox to behave like Vim.

Vimperator is an extremely useful addon for Firefox, especially that you can call up an external editor (GVim) to edit form text fields and the like. Use it for blogging, interfacing to mysql via phpmyadmin or web forms, etc.

Vimkeybindings

Vimkeybindings is a small addon that adds only Vim hjkl keys, much like Konqueror, and g and G as home and end replacement. Quite useful for those who want Firefox not to change its behaviour much, need extensions which rely on the status bar (standard status bar is disabled by Vimperator), etc.

Other information

Some related information follows:

  • Mozilla has a reference on how to configure key bindings, if you want to configure Firefox yourself.
  • In Firefox, press F7 to toggle the text cursor on/off ("caret browsing").
  • Calmar on Firefox, Vim more information.
  • Calmar on Opera can configure Vim key bindings in Opera.
  • Mouseless Browsing add-on numbers each link; can click on links without a mouse.
  • Vimium provides Vim key bindings for Google Chrome (and Chromium).

Old information

The following is from 2002, and may not be useful for recent versions of Firefox.

Finding the arrow keys on a laptop is annoying, when you simply want to scroll the web page. Here is how to customize Mozilla browsers to use the Vim h/j/k/l keys.

  • 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"> 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>

Comments

I found this didn't work in userHTMLBindings.xml, but adding relevant lines in htmlBindings.xml works great (see bug 201011).


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 (Unix 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).


The tip worked on Netscape 7.0 on Windows. But it seemed like it worked only after removing the couple of ";' in the initial two lines which seemed unexpected.


Using Vim keys in Opera (tested with 7.23 and 7.50). Close Opera while performing following modifications, which allow keys j/k to scroll up/down and h/l to go to previous/next page in history. Keys J/K/H/L navigate links in page.

; In directoy ~/.opera/keyboard/ there is file unix_keyboard.ini or something like that
; Under section [Application] add following items:
k=Scroll up
k shift=Navigate up
j=Scroll down
j shift=Navigate down
l=Forward | Fast Forward
l shift=Navigate right
h=Back
h shift=Navigate left

Around Wikia's network

Random Wiki