What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

I navigate with Ctrl-n,p,f,b (readline/emacs keys) so that I don't have to move my hands too much and get RSI again. Is there a way to disable Ctrl-b being hotkey for bold?

EDIT: Note that this is not just an emacs thing. Standard web browsers like Firefox and Chrome use things like Ctrl-k and Ctrl-l to navigate to the Google search bar and address bar respectively.

share|improve this question
    
These are called "access keys", and are implemented with the "accesskey" attribute. You might like to add this as a tag. –  mjs Nov 14 '09 at 17:46
3  
Agree. overriding ctrl bindings should never be done haphazardly. –  Adam Bergmark Apr 22 '11 at 14:54
10  
+1 please add a preference to turn it off, or change the keys to something that doesn't interfere, or just remove the feature altogether. I run into this problem several times a day, and it's starting to piss me off. –  Abhi Beckert Dec 25 '11 at 20:28
    
In Firefox I often usek Ctrl-k to navigate to the Google search bar. In Chrome I often use Ctrl-l to navigate to the address bar. I hate that I cannot use these while asking or answering a question. –  Michael McGowan Feb 16 '12 at 16:32
    
Historically, preferences are frowned upon. Also, many more people want the key bindings than don't want them, so it's likely that you'll have to come up with a user-side solution such as a userscript in order to overcome this issue. –  Adam Davis Feb 16 '12 at 16:53
4  
@AdamDavis "many more people want the key bindings than don't want them" Do you have any evidence to back up that claim? –  Michael McGowan Feb 16 '12 at 17:06
    
@MichaelMcGowan Nope. Other than it was included by default in the WMD editor, we've had it for years, and questions suggesting changing or removing them never get more than a handful of votes. If it were not widely valued, or if it regularly got in the way of people's usage of the site, it would get a lot more scrutiny every time this came up. This request is nearly 3 years old and only has 18 supporters, out of millions of Stack Overflow users, who would surely complain if it was an annoying problem. –  Adam Davis Feb 16 '12 at 17:17
    
@MichaelMcGowan - control-b to make text bold is I think a much, much more common operation than whatever crazy emacs voodoo OP is talking about. Control-b for bold works in MS Word, Gmail, Google Docs, etc. Adam Davis is most likely right in his assertion, but I doubt anyone has stats to back it up. –  Adam Rackis Feb 16 '12 at 17:17
3  
@AdamRackis Neither Gmail nor Google Docs (Chrome/OS X) does anything special with Ctrl-B for me. Contrariwise, does any editor without this feature have people requesting it? Wikipedia doesn't work like this, nor does Blogger, Facebook, Twitter... –  mjs Feb 19 '12 at 9:15
    
The CTRL + H is also annoying, since muscle memory expects character deletion (instead you get the Heading shortcut). –  courteous Nov 20 '12 at 10:48
    
I should add to this. The 'escape' key is mapped to 'browser back'. I pressed it to cancel a search-in-page operation. Annoying. –  Joe Dec 27 '12 at 21:11

5 Answers 5

Bookmarklet:

javascript:(function(a,p){function i(e){e.stopPropagation()};p[a]('keydown',i,!0);p[a]('keypress',i,!0);p[a]('keyup',i,!0);})('addEventListener',$('#wmd-input').parent()[0]);

User Script:

// ==UserScript==
// @name           Cya WMD shortcuts
// @namespace      Rob W
// @version        1.0
// @match          http://stackoverflow.com/*
// @match          http://*.stackoverflow.com/*
// @match          http://superuser.com/*
// @match          http://meta.superuser.com/*
// @match          http://serverfault.com/*
// @match          http://meta.serverfault.com/*
// @match          http://askubuntu.com/*
// @match          http://meta.askubuntu.com/*
// @match          http://*.stackexchange.com/*
// @match          http://answers.onstartups.com/*
// @match          http://meta.answers.onstartups.com/*
// @match          http://stackapps.com/*
// @run-at         document-end
// @grant          none
// ==/UserScript==

(typeof unsafeWindow !== 'undefined' ? unsafeWindow : window).$(function() {
    var p = document.getElementById('wmd-input');
    if (!p) return;
    p = p.parentNode;
    function ignore(e){e.stopPropagation();}    
    p.addEventListener('keydown', ignore, true);
    p.addEventListener('keypress', ignore, true);
    p.addEventListener('keyup', ignore, true);
});

Technical details

  • In the W3C event model, JavaScript events are fired in two ways:
    • Capture (The events are fired, from the top of the document to the target)
    • Bubble (The events bubble from the target to the top of the document).
  • In wmd.js, the events are bound using addEventListener, in the bubbling phase.
  • The event is added to the parent node of the element, with the capturing flag. Inside the event listener, event.stopPropagation(); is called, to stop the event from propagating further.
  • As a result, all WMD shortcuts are disabled.

Chrome extension

  1. Create a directory, and store the following two files in it.
  2. Visit chrome://extensions/
  3. Enable Developer mode
  4. Click on the button Load unpacked extension....
  5. Select the directory from step 1.

manifest.json

{
    "name": "Cya WMD shortcuts",
    "manifest_version": 2,
    "version": "1.0",
    "content_scripts": [{
        "js": ["contentscript.js"],
        "matches": [
            "http://stackoverflow.com/*",
            "http://*.stackoverflow.com/*",
            "http://superuser.com/*",
            "http://meta.superuser.com/*",
            "http://serverfault.com/*",
            "http://meta.serverfault.com/*",
            "http://askubuntu.com/*",
            "http://meta.askubuntu.com/*",
            "http://*.stackexchange.com/*",
            "http://answers.onstartups.com/*",
            "http://meta.answers.onstartups.com/*",
            "http://stackapps.com/*"
        ]
    }]
}

contentscript.js

var p = document.getElementById('wmd-input');
if (p) {
    p = p.parentNode;
    var ignore = function(e){e.stopPropagation();};
    p.addEventListener('keydown', ignore, true);
    p.addEventListener('keypress', ignore, true);
    p.addEventListener('keyup', ignore, true);
}

 

share|improve this answer
    
PS. Between the creation of this question and this answer, this feature request has been approved. Ctrl+shift+* and Ctrl+alt+* key combinations are not affected, by default. –  Rob W Feb 23 '12 at 17:57
    
@blahdiblah Not tested, but you could insert if(e.ctrlKey) before e.stopPropagation(); so that the script is only activated for Ctrl + * key combinations. –  Rob W Oct 5 '12 at 12:40
    
As per your suggestion, changing i(e) and ignore(e) to ignore(e){e.metaKey && e.stopPropagation();} removes the problematic keyboard shortcut behavior, but doesn't trigger a captcha all the time. –  blahdiblah Oct 8 '12 at 19:11
    
how can i use it in chrome? –  freestyler Jan 18 '13 at 12:45
    
@freestyler I've updated my answer with the source code for the Chrome extension. –  Rob W Jan 18 '13 at 13:18
1  
@RobW Thank you. As a emacs user, It's really useful. –  freestyler Jan 18 '13 at 14:04
    
@RobW thanks, this is fantastic! i use cmd+L compulsively to to go the location bar in chrome on a mac, and it drives me batty that SE thinks its a good idea to override default shortcuts. cmd+R works now too, to refresh the page. –  Jeff Apr 1 '13 at 3:17
    
@Jeff I am actually used to Ctrl+L for links. I've got your issue with Chrome's Developer tools: In the console, Ctrl + L is overridden. I've found that Ctrl+K focuses the omnibar with search. Then it's a matter of entering the keywords (if you were really going to search) or hitting backspace and type the full URL to continue. –  Rob W Apr 1 '13 at 8:06
    
great help, in Firefox/Vimperator the webpage Ctrl+I shortcut interferes with Vimperator's edit-in-external-editor shortcut. In some Firefox versions this results in inserting a emphasized text before opening gvim - in current versions gvim is completely blocked. Exorbitantly annoying. As a quickfix opening your booklet code via ESC :o works fine in Vimperator. –  maxschlepzig Jan 12 at 11:02
    
Bookmarklet does not work anymore with current so site/Firefox 27. –  maxschlepzig Apr 12 at 7:24

I feel for you, as I have a similar problem... if not worse :-(

On contemporary Hungarian keyboards, some special characters are mapped to key combinations involving the Right Alt (aka AltGr) key. Such as

  • [ to RightAlt+F,
  • ] to RightAlt+G ...which opens the "Insert Image" dialog on SO,
  • { to RightAlt+B ...which evokes strong text on SO,
  • } to RightAlt+N.

Do I need to explain how terrible it is to try to write e.g. Java code with this keyboard mapping? Lately I realized that the Search box doesn't have these mappings - so if I need a closing square bracket or an opening curly bracket (and there is no code snippet around in the actual post to copy from), all I need is to switch to the Search box, type the character, select it, Ctrl+X, back to the Editor box, Ctrl+V...

Even though this is not an answer to your question in the strict sense, at least (hopefully) it shows that this problem is not as marginal as it may seem at first sight.

share|improve this answer

Here is Rob W's script, updated to only block cntrl-* and fixed so that it works with NinjaKit which is a Safari extension for running user scripts. Re-did it for this question on Ask Different

NinjaKit: https://github.com/os0x/NinjaKit

Script:

// ==UserScript==
// @name           Cya WMD shortcuts
// @namespace      Rob W
// @version        1.0
// @include          http://apple.stackexchange.com/*
// @include          http://stackoverflow.com/*
// @include          http://superuser.com/*
// @include          http://meta.superuser.com/*
// @include          http://serverfault.com/*
// @include          http://meta.serverfault.com/*
// @include          http://askubuntu.com/*
// @include          http://meta.askubuntu.com/*
// @include          http://*.stackexchange.com/*
// @include          http://answers.onstartups.com/*
// @include          http://meta.answers.onstartups.com/*
// @include          http://stackapps.com/*
// @run-at         document-end
// @grant          none
// ==/UserScript==
(function () {
    var p = document.getElementById('wmd-input');
    console.log("wmd-input:" + p);
    if (p) {
        p = p.parentNode;

        function ignore(e) {
            if (e.ctrlKey) {
                e.stopPropagation();
            }
        }
        p.addEventListener('keydown', ignore, true);
        p.addEventListener('keypress', ignore, true);
        p.addEventListener('keyup', ignore, true);
    }
})();
share|improve this answer
    
Only started working after deleting the "Demo" script. Safari 6.0.5. –  courteous Oct 13 '13 at 10:22

Most likely there is; check in your browser's settings (or at least tell us what browser you are using).

If there isn't you can easily create (or have someone create here on meta) a greasemonkey script to remove the accesskey="" attributes from HTML tags. Again, not all browsers support greasemonkey (Firefox and Chrome do, possibly others do too).

If you are asking for some kind of user setting in your account page then I'm fairly sure it's not going to happen, sorry. Very very few people "navigate" web pages using emacs keys (in fact I find this kinda funny :P) and when it comes to user interfaces less is always better: you don't want to offer 5 thousand options to your user when the average user cares about 1 or 2.

share|improve this answer
2  
I don't navigate the page with emacs keys. Just the textboxes. I agree, less is better. Which is why I don't understand why SO takes over ctrl-b et.al.. It's horrible. Why would I want to use arrow keys or the mouse? Oh well, I guess I'll have to look into a greasemonkey script. Hmm... there are no accesskey attributes that I can see. –  Thomas Apr 7 '10 at 18:36
    
+1 for preferences setting to disable accesskeys in textboxes. –  Simeon Fitch Apr 15 '10 at 3:08

With Firefox 27 the already posted Greasemonkey scripts and bookmarklet don't work.

The bookmarklet used to work, but it doesn't anymore.

What does work is using anti-keygrabber.user.js (blog entry). In case it does not contain all keycodes you want to be excluded from being grabbed by a webpage you can easily add them.

For example to also exclude Ctrl+I you just have to add:

case 73:

to the first switch statement:

switch (e.keyCode) {
  case 87: // W - close window
  case 84: // T - open tab
  case 76: // L - focus awesome bar
  case 74: // J - open downloads panel
    e.stopImmediatePropagation();
    return;
}
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .