最近给Firefox这一快捷键坑了几次。恰好发现在CMU也有人遇到类似的烦恼,找到一篇基于Linux的教程。
我使用的是Windows,所以根据自己的情况做了些修改,成功了。小众需求就犯懒直接将笔记贴上了,如果有谁用得上的话,我写个中文版。
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)
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
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 thenCtrl-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 changingreserved="true"
toreserved="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
In URI panel, enter about:support
Click “Clear startup cache…” on the right, and click restart. (opened pages won’t be lost)
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).
https://www.math.cmu.edu/~gautam/sj/blog/20220329-firefox-disable-ctrl-w.html