[Firefox/快捷键] 禁用Ctrl-W快捷键

最近给Firefox这一快捷键坑了几次。恰好发现在CMU也有人遇到类似的烦恼,找到一篇基于Linux的教程。
我使用的是Windows,所以根据自己的情况做了些修改,成功了。小众需求就犯懒直接将笔记贴上了,如果有谁用得上的话,我写个中文版。

Disabling the Ctrl-W shortcut on Firefox

Many vim users use ctrl-w to delete a word. Unfortunately on Firefox, this closes the current tab. So if you’re editing a text area / filling out a form you may accidentally close the tab.

There’s no option to change or disable default keyboard shortcuts (Firefox 98, 2022-03-29 // Firefox 117依然不支持). So if you want to do it, you need to edit files manually.

To disable ctrl-w shortcut in Firefox, you need to manually edit the file:

  • /usr/lib/firefox/browser/omni.ja (Linux) .
  • "/c/Program Files/Mozilla Firefox/browser/omni.ja" (Windows)

Modify the File

Run git bash in administration mode.

First unzip it to a temporary directory:

mkdir /tmp/firefox-omni
cd /tmp/firefox-omni
unzip "/c/Program Files/Mozilla Firefox/browser/omni.ja"

Now you need to edit ./chrome/browser/content/browser/browser.xhtml to make your changes. You can change as many shortcuts as you want here. The ctrl-w key is called close-shortcut. You can either

  • comment out the offending line, or
  • change modifiers="accel,shift" to require ctrl-shift-w to close tabs.

Note, the above instructions only make Ctrl-W an unreserved shortcut. This means extensions can now remap it. If you don’t have any extensions that remap it then Ctrl-W will still close your current window.

If you’d like to simply disable Ctrl-W, then just comment out the above shortcut definitions entirely (instead of only changing reserved="true" to reserved="false" as I suggest above).

Here is how to comment it out:

<key id="key_close" data-l10n-id="close-shortcut" command="cmd_close" modifiers="accel" reserved="true"/>

Now switch to root, and install your changes:

cd /tmp/firefox-omni
zip -0DXqr /tmp/omni.ja * # I have install `zip` into DELL
cd "/c/Program Files/Mozilla Firefox/browser"

cp ./omni.ja ./omni.ja.bkup # backup

cp /tmp/omni.ja ./omni.ja # TOCHECK: if the first path is correct
rm -r /tmp/omni.ja /tmp/firefox-omni

Clear Firefox Start Cache and Restart

In URI panel, enter about:support

Click “Clear startup cache…” on the right, and click restart. (opened pages won’t be lost)

Done🍺

Note: You will have to do this every time you reinstall firefox. I automated the above into a script. First save firefox-omni.patch as ~/local/src/firefox-omni.patch, and then download and run this script as a normal users (that has sudo privileges).

Reference

https://www.math.cmu.edu/~gautam/sj/blog/20220329-firefox-disable-ctrl-w.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值