【问题标题】:How to close tabs to the right using vimperator?如何使用 vimperator 关闭右侧的标签?
【发布时间】:2016-02-01 13:02:26
【问题描述】:

我正在使用 Firefox,并安装了 vimperator。很好,但我找不到使用热键关闭右侧标签的方法。你能告诉我怎么做吗?谢谢。

【问题讨论】:

  • 对不起,我的问题不清楚,我的意思是如何配置热键来替换当前选项卡上的“向右关闭选项卡”菜单项。

标签: firefox vimperator


【解决方案1】:

全部关闭到右/左。

将以下代码放入您的.vimperatorrc 文件中。它分别定义了命令:closealltoright:closealltoleft 以及绑定v>v。在以“map”开头的行中根据需要更改绑定。

js <<EOF

closeAllToRight = function () {
    var current = tabs.getTab();
    var currentIx = tabs.index(current);
    var nexttab = current.nextElementSibling;
    var N = tabs.count;
    var numToClose = N - (currentIx + 1);
    tabs.remove(nexttab, numToClose);
}

closeAllToLeft = function () {
    var current = tabs.getTab();
    var currentIx = tabs.index(current);
    var firsttab = tabs.getTab(0);
    var N = tabs.count;
    var numToClose = currentIx;
    tabs.remove(firsttab, numToClose);
}

EOF

" close tabs to left
map v< :js closeAllToLeft()<CR>
" close tabs to right
map v> :js closeAllToRight()<CR>

command! closealltoright :js closeAllToRight()
command! closealltoleft :js closeAllToLeft()

我已将这两个命令上传为Gist


五指版。

command! closetabstoleft
    \ -description "Close all tabs to the left of the current tab"
    \ -js
    \ var firstTab = tabs.getTab(0);
    \ var numToClose = tabs.getTab().dactylOrdinal - 1;
    \ tabs.remove(firstTab, numToClose);
command! closetabstoright
    \ -description "Close all tabs to the right of the current tab"
    \ -js
    \ tabIndex = tabs.getTab().dactylOrdinal - 1;
    \ var nextTabIndex = tabIndex + 1;
    \ var firstTab = tabs.getTab(nextTabIndex);
    \ var N = tabs.allTabs.length;
    \ var numToClose = N - nextTabIndex;
    \ tabs.remove(firstTab, numToClose);

map v< -ex closetabstoleft
map v> -ex closetabstoright

为方便起见,我已将这些放在gist 中。

更多选项卡命令可以在我的Pentadactyl folder 中找到(命令和绑定在.pentadactylrc,但可能依赖于utils.js 中定义的函数)。

【讨论】:

  • @pyrocrasty 你知道我在哪里可以找到 vimperator API 吗?我的意思是您正在使用诸如“标签”、“标签。删除”等元素。它们记录在哪里?
  • @ka3ak:恐怕他们不是。您必须查看源代码和/或从命令行以交互方式探索。选项卡和缓冲区功能之类的东西很容易。只需在命令行上输入tabs.buffers. 并使用制表符完成来查看可用的方法。如果不全面了解(未记录的)vimperator/dactyl 架构,其他事情就很难解决。如果您对 webdev(或者更好的 FF 扩展开发)有经验,这可能会更容易一些,但我没有。如果我需要一些东西,通常是源代码查找和命令行试错的碰巧问题。
  • @ka3ak:您可以查看我的 .pentadactyl 文件夹(链接在答案中),看看如何做一些我已经解决的事情(尤其是 .pentadactylrcutils.js 文件)。不幸的是,代码可能需要修改才能在 vimperator 上运行。通常它相当简单(例如将dactyl. 更改为liberator.),但有时可能更难。我确实有一个.vimperatorrc 文件,但里面没有太多内容。
  • 更正:在我上面的评论中,buffers. 应该是buffer.
【解决方案2】:

map &lt;your_key_binding&gt; gt :bd -s left&lt;CR&gt; 添加到您的 vimperatorrc。

说明:

gt 切换到下一个右侧选项卡,:bd -s left 删除此选项卡并在此之后切换到左侧选项卡。

【讨论】:

  • 对不起,我的问题不清楚,我的意思是如何配置热键来替换当前选项卡上的“向右关闭选项卡”菜单项。
猜你喜欢
  • 1970-01-01
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
  • 2020-05-11
  • 1970-01-01
  • 1970-01-01
  • 2012-04-18
相关资源
最近更新 更多