位元詩人 技術雜談:KeySnail - Surf the Net with Emacs Power

Facebook Twitter LinkedIn LINE Skype EverNote GMail Yahoo Email

Some people might prefer keyboard strokes over mouse clicks. Some people may miss convenient Emacs-style keybindings. Although we cannot do everything in Emacs, we can surf the Net in Emacs fashion with KeySnail. KeySnail is a Firefox extension for Emacs-stype keybindings. With KeySnail, you can scroll web pages down and up with Ctrl-v and Meta-v and edit text like using Emacs. There are some plugins for KeySnail to enhence its function.

To install KeySnail, go to KeySnail page and download keysnail.xpi. Next, open the xpi file with Firefox and install it. Now, restart your Firefox. The first time restarting your Firefox, KeySnail will ask you to create a new init file. There are four available schemes:

  • Emacs / w3m
  • Lightweight Emacs for Mac OS X
  • Little vimperator
  • Empty

If you are using OS X, Lightweight Emacs is recommanded to avoid keybinding conflicts; otherwise, standard Emacs / w3m is favored. The default init file is .keysnail.js or _keysnail.js; the latter is prefered for Windows users. Then, you can start using KeySnail.

Here are some basic keybindings of KeySnail.


back  forward  reload
 B       F       R
+-------- location bar -------------+-- search bar --+
+----------- C-x l -----------------+---- C-x g -----+
 previous tab  |                     |   next tab
----- h -------+                     +----- l --------
                  top of the page
                         g
                   previous page
                        M-v
                   previous line
                     C-p or k

move right C-b                       C-f move left

                     next line
                     C-n or j
                     next page
                        C-v
                  end of the page
                         G
{{< / highlight >}}

There are some special keybindings of KeySnail.  Press `<F2>` to toggle off and on all KeySnail keybindings.  Press `Ctrl-g` to cancel current key input, the same life saver in Emacs.  For a complete list of KeySnail keybindings, press `<F1> b`.

## KeySnail Plugins

There are several KeySnail plugins to enhance the function of KeySnail.  Among them, HoK is highly recommended.  With HoK, you can navigate the links of a web page without mouse clicks.  To install HoK, go to [KeySnail plugins page](https://github.com/mooz/keysnail/wiki/Plugin) and install HoK from the right-click menu of Firefox.

Then, edit *.keysnail.js* file, add the following code in reserved area (in top of the file).  You can get the code from KeySnail plugin manager from Firefox menu.

```javascript
// HoK
key.setViewKey('e', function (aEvent, aArg) {
    ext.exec("hok-start-foreground-mode", aArg);
}, 'Hok - Foreground hint mode', true);

key.setViewKey('E', function (aEvent, aArg) {
    ext.exec("hok-start-background-mode", aArg);
}, 'HoK - Background hint mode', true);

key.setViewKey(';', function (aEvent, aArg) {
    ext.exec("hok-start-extended-mode", aArg);
}, 'HoK - Extented hint mode', true);

key.setViewKey(['C-c', 'C-e'], function (aEvent, aArg) {
    ext.exec("hok-start-continuous-mode", aArg);
}, 'Start continuous HaH', true);

key.setViewKey('c', function (aEvent, aArg) {
    ext.exec("hok-yank-foreground-mode", aArg);
}, 'Hok - Foreground yank hint mode', true);
// End of Hok
{{< / highlight >}}

Reload init file with `Ctrl-Meta-r` to makes the modification effective.

Click `e`, you will see some highlighted letters over links, type the letters to go into the link.  Click `E` to load the link in background.  Click `;` for advanced operation on hints.

*bmany* is another recommended plugin.  After installation of bmany, add the following code to the **bottom** of *.keysnail.js* file.

```javascript
// bmany
key.setViewKey([':', 'b'], function (ev, arg) {
    ext.exec("bmany-list-all-bookmarks", arg, ev);
    }, 'bmany - List all bookmarks');

key.setViewKey([':', 'B'], function (ev, arg) {
    ext.exec("bmany-list-bookmarklets", arg, ev);
    }, "bmany - List all bookmarklets");

key.setViewKey([':', 'k'], function (ev, arg) {
    ext.exec("bmany-list-bookmarks-with-keyword", arg, ev);
    }, "bmany - List bookmarks with keyword");

key.setViewKey([':', 't'], function (ev, arg) {
    ext.exec("bmany-list-bookmarks-with-tag", arg, ev);
    }, "bmany - List bookmarks with tag");
// End of bmany
{{< / highlight >}}

Press `: b`, there will be a list of Firefox bookmarks.  You can scroll the list by `Ctrl-n` or `Ctrl-p` and search pattern by keywords.