平衡点


2017/01/26

_ Vimperator から VimFx に代えてみた.

sid に Firefox 51 が落ちてきて,例によって vimperator が動かなくなった.

「とりあえず ESR 使えば?」「次の ESR って 2017 年 3 月リリース予定の 52 だよね」とか言われてて,なかなか.

とはいえ,普段の環境が vimperator 的な操作にドップリなので,どうしたモンだろうか,としばし悩んだが,VimFx という拡張を見つけた.

Even before Vimium there was Vimperator for Firefox. In my opinion, Vimperator has too many features and aggressively changes the default Firefox appearance and behavior. Vimium is exactly what I need in terms of added functionality, but for Chrome. That’s why I decided to develop a similar extension for Firefox.

[from:akhodakivskiy/VimFx: Vim keyboard shortcuts for Firefox]

ということで,試してみることに.

インストールと設定,など.

軽くてびっくりした.それだけ vimperator って色々なコトをやってるんですね,というか. e10s にも対応していて,使用にも問題無さげ.

  • 基本的なキーバインドは既に設定されている.「?」 を押すと help 出るのもなかなか良さげ.
  • Addon ⇒ preferences でそれなりに設定できるのも良い.
  • Hint モードでの色使いも良い(というか,vimperator だとそもそも文字小さいよねぇ...).

違和感,というか慣れが必要なのは

  • ロケーションバーで検索,移動を操作
  • 通知等が右下に出る.
  • いわゆるコマンドモードが無い? ⇒ 「:」 だと GCLI が起動してきた.restart ぐらいはこれでイケる.

Vimiumなんかはコマンド入力時に入力欄が全面に出てきたので違和感がなかったけれど, ちょっと視線が上下する.慣れって怖い. でも,vim のコマンドラインって下にあるじゃん...

カスタムコマンド等

vimperator のヘビーユーザではないので,無いと途方に暮れるのは

  • プロキシの切り替え
  • URL, title のコピー

といった所.このぐらいなら,まあ,適当に作れる.

現在の ~/.config/vimfx/config.js は以下

// config - based on
const {classes: Cc, interfaces: Ci, utils: Cu} = Components
Cu.import("resource://gre/modules/XPCOMUtils.jsm")
XPCOMUtils.defineLazyModuleGetter(this, "Preferences", "resource://gre/modules/Preferences.jsm")
const gClipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
// override default settings
Preferences.set({
    "devtools.chrome.enabled" : true,
    "browser.urlbar.filter.javascript" : false,           // bookmarklet を使うのに必要
    "findbar.modalHighlight": false,
    "findbar.highlightAll": false,
});
// helper functions
let {commands} = vimfx.modes.normal
let set = (pref, valueOrFunction) => {
    let value = typeof valueOrFunction === "function"
        ? valueOrFunction(vimfx.getDefault(pref))
        : valueOrFunction
    vimfx.set(pref, value)
}
let map = (shortcuts, command, custom=false) => {
    vimfx.set(`${custom ? "custom." : ""}mode.normal.${command}`, shortcuts)
}
// options
set("prevent_autofocus", true)
set("mode.normal.copy_current_url", "y");
// custom command
vimfx.addCommand({
    name: "goto_addons",
    description: "Addons",
}, ({vim}) => {
    vim.window.BrowserOpenAddonsMgr()
})
map(",a", "goto_addons", true)
//
vimfx.addCommand({
    name: "goto_preferences",
    description: "Preferences",
}, ({vim}) => {
    vim.window.openPreferences()
})
map(",p", "goto_preferences", true)
//
vimfx.addCommand({
    name: "goto_downloads",
    description: "Downloads",
}, ({vim}) => {
    vim.window.DownloadsPanel.showDownloadsHistory()
})
map(",d", "goto_downloads", true)
//
vimfx.addCommand({
    name: "goto_config",
    description: "Config",
}, ({vim}) => {
    vim.window.switchToTabHavingURI("about:config", true)
})
map(",c", "goto_config", true)
//
vimfx.addCommand({
    name: "search_bookmarks",
    description: "Search bookmarks",
    order: commands.focus_location_bar.order + 1,
}, (args) => {
    let {vim} = args
    let {gURLBar} = vim.window
    gURLBar.value = ""
    commands.focus_location_bar.run(args)
    gURLBar.value = "* "
    gURLBar.onInput(new vim.window.KeyboardEvent("input"))
})
map("b", "search_bookmarks", true)
//
vimfx.addCommand({
    name: "copy_org",
    description: ""[[URL][title]]"でURLコピー",
    category: "location",
}, ({vim}) => {
    let url = vim.window.gBrowser.selectedBrowser.currentURI.spec
    let title = vim.window.gBrowser.selectedBrowser.contentTitle
    let fmt = "[["+url+"]["+title+"]]"
    gClipboardHelper.copyString(fmt)
    vim.notify("Copied String: "+ fmt)
})
map("co", "copy_org", true)
//
vimfx.addCommand({
    name: "copy_rd",
    description: ""((<"title"|URL:URL>))"でURLコピー",
    category: "location",
}, ({vim}) => {
    let url = vim.window.gBrowser.selectedBrowser.currentURI.spec
    let title = vim.window.gBrowser.selectedBrowser.contentTitle
    let fmt = "((<\""+title+"\"|URL:"+url+">))"
    gClipboardHelper.copyString(fmt)
    vim.notify("Copied String: "+ fmt)
})
map("cr", "copy_rd", true)
//
vimfx.addCommand({
    name: "foxyproxy_click_toolbar_button",
    description: "FoxyProxy",
}, ({vim}) => {
    vim.window.document.getElementById("foxyproxy-toolbar-icon").click()
})
map(".p", "foxyproxy_click_toolbar_button", true)

まとめ?

とりあえずコレ使ってみることにする.ライトユーザには充分じゃないかな.

(2017/01/28追記) proxy の切り替えは駄目っぽかったので削除.代わりにFoxyProxy Standard :: Add-ons for Firefoxを入れて,".p" で Foxyproxy のツールバーボタンを押すようにしてみた.


連絡先など
最近の日記
一覧
2006|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|02|03|04|08|09|10|11|12|
2013|01|02|03|04|05|06|08|09|10|11|12|
2014|01|02|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|09|10|
2016|02|03|
2017|01|02|03|05|06|07|09|11|12|
2018|03|06|07|10|11|12|
2019|01|02|03|04|05|07|10|12|
2020|01|02|03|04|05|08|09|10|11|12|
2021|01|02|03|05|06|07|08|09|11|12|
2022|01|02|03|04|05|06|08|10|11|12|
2023|02|03|04|06|08|09|11|12|
2024|01|02|03|
Back to Top ▲