14

As a tmux user, there is a lot of Ctrl+b going on. Also a lot of Firefox.

It's safe to say I never, ever want to see the book mark vertical bar. No interest. Never had any in 20 years of computer use.

Is there any way to disable Ctrl+b in Firefox without using a plug-in?

Mwiza
  • 7,780
  • 3
  • 46
  • 42
datakid
  • 2,293
  • 5
  • 23
  • 35

3 Answers3

3

I've been able to disable the Ctrl+B shortcut by using the Shortkeys extension.

Its configuration can be a little cumbersome, so here's a quick guide:

  • In the extensions page (about:addons), click the ... menu next to the Shortkeys entry, and select "Preferences"
  • Add a new shortcut:
    • In the "Shortcut" column, type "Ctrl+B".
    • In the "Label" column, enter something like "Disable bookmarks sidebar".
    • In the "Behavior" column, select the "Do nothing" entry
  • Don’t foget to click the Save shortcuts button at the bottom of the page!

Note: This only works in the context of a web page. The default Firefox action will still execute if you press Ctrl+B while the cursor is e.g. in the URL bar or the search bar. But for me it's a great improvement already!

waldyrious
  • 3,683
  • 4
  • 33
  • 41
1

Since Firefox 72, this needs to be done with autoconfig.js. See Firefox documentation and example usage.

OLD WAY: This can be accomplished using userChrome.js

Use the following code:

var key = document.getElementById('viewBookmarksSidebarKb');
if (key) key.remove();

Credit - I found this thanks to this answer https://superuser.com/questions/1318336/how-to-disable-ctrlq-shortcut-in-firefox-on-linux/1348082#1348082

AdamS
  • 209
  • 2
  • 8
  • 1
    Unfortunately, since Firefox 72 (January 2020) this option doesn't work anymore :( – waldyrious Sep 08 '21 at 17:14
  • 1
    @waldyrious Thanks for adding the comment. It still works using a slightly different way so I updated my answer. – AdamS Sep 12 '21 at 18:18
-1

Many topics on this and none seem to work, so I've just hand-rolled something that does seem to work. This is JavaScript-only, with no try/catch blocks for clarity.

Goal: In contentEditable DIV, prevent Firefox from processing Ctrl-B, so we can use it to set the text content to BOLD.

Basic idea is to stop propagation at the body (suppress bubble up to browser), while setting bold at the control (allowing bubble-down to text that is being edited in the div). Solution is FF-only, since that is the question, but I can extend it to Webkit and IE on request.

HTML:

<body onkeydown="bodyKeyHandler(this, event);">
    <div contentEditable="true" onkeydown="editorKeyHandler(event);"></div>
</body>

JAVASCRIPT:

function bodyKeyHandler(o,e) {
    var c = e.ctrlKey;
    var k = e.which;
    if (e.ctrlKey) { 
        switch ( k ) {
            case 17:
                e.preventDefault();
                o.stopPropagation();
                break;
        }
    }
}

function editorKeyHandler(e) {
    var c = e.ctrlKey;
    var k = e.which;
    if (c) { 
        switch ( k ) {
            case 17:
                document.execCommand("bold");
                break;
        }
    }
}

One important warning, when fiddling with this in FF, injecting alert() to see what's happening will break it, because the alert popup will capture and bubble the event to the browser! To see it working, remove all tracing.

imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • This only works when in a web page that has code like this to bind the `Ctrl+B` shortcut using JavaScript. This is the case, for instance, in StackOverflow and GitHub text boxes (try focusing the answer box below and pressing Ctrl+B to see it in action). However, the original question is about disabling the `Ctrl+B` shortcut across the browser, regardless of the page one's in and what element is currently focused. This solution, unfortunately does not do that. – waldyrious Sep 08 '21 at 16:50