1

I have used Karabiner to change a key combination but the problem is, it doesn't work exactly as I want.

For example, using Karabiner, I have mapped alt to cmd and vice versa. But what Karabiner does is, it "tricks" the OS to make it think that I have pressed alt, whenever I press cmd.

This isn't the behaviour I want. The behaviour I want is, whenever I press cmd<-, I want the system to think that I have indeed pressed cmd, but instead of moving the cursor to the beginning of the line, I want it to move it to the previous word.

It is possible to do this maybe messing with some system files and stuff?

  • Hmm You may restrict the solution I offered in the related question to particular apps. – klanomath Oct 3 '15 at 17:42
  • @klanomath That may work, albeit not very practically. The behaviour I want is, I want cmd<- act as Ctrl<- of a PC keyboard. That is; make the cursor move to the previous word. ... – Utku Oct 3 '15 at 17:44
  • @klanomath ... Note that I am talking about cursor because I want this behaviour to happen only on text fields. The reason is, for example I am using cmd<- as "Show Previous Tab" shortcut on Safari. – Utku Oct 3 '15 at 17:46
  • @klanomath I feel like there's gotta be some magic to do it by messing with some system files and stuff but the problem is, I don't know how to do it or is it really possible. – Utku Oct 3 '15 at 17:49
  • Probably you indeed have to hack some frameworks (which may overwritten by the next system update). Do you need the solution in EVERY app. I think the most problematic apps are browsers because they may offer text field as well as tab/window navigation with those shortcuts – klanomath Oct 3 '15 at 18:08
1

You can change the text editing bindings for Cocoa apps with DefaultKeyBinding.dict. This will work for almost all applications where the ⌘ command+← left and ⌘ command+→ right worked before. (The only way it wouldn't work is if the application creator reimplemented those shortcuts from scratch, which is doubtful as it would be much easier to just use the versions that come free with a textfield.)

  1. If the directory ~/Library/KeyBindings/ does not exist, create it.

  2. Create the file DefaultKeyBinding.dict in that directory with contents like this:

    {
        "@\Uf702" = moveWordBackward:;
        "@\Uf703" = moveWordForward:;
        "~\Uf702" = moveToBeginningOfLine:;
        "~\Uf703" = moveToEndOfLine:;
    }
    

    The @ refers to the Command key, ~ is Option, \Uf702 is Left, and \Uf703 is Right. The selectors on the right-hand side are the same ones used in the default file, /System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict, but switched around to match what you said in your question.

  3. Restart an application for the changes to take effect in it.

Here's an in-depth guide to the Cocoa Text System that should help explain what's going on.

  • Thanks. Could you also post some links so that I will understand what exactly I am doing by doing these and understand how these work? – Utku Oct 3 '15 at 18:15
  • 1
    @Utku: Edited. Hopefully that helps. – 0942v8653 Oct 3 '15 at 18:22
  • 1
    @Utku Developer Apple – klanomath Oct 3 '15 at 18:22
  • 1
    @Utku: There is no real way to tell except for trying it out. Generally, any app that is Mac-only or made natively should use Cocoa Text System, and any app that uses GTK+ or Qt should not. I don't think that Firefox uses it (it is GTK+) but it must have some sort of workaround to make DefaultKeyBinding.dict work. – 0942v8653 Oct 3 '15 at 18:59
  • 1
    @Utku: I don't really know. I would say that it probably does use the Cocoa Text System but overrides shortcuts for the address bar (It doesn't disable them completely—I don't have your settings for navigating back and forward in history and the editing bindings still work for me). – 0942v8653 Oct 3 '15 at 19:44

You must log in to answer this question.

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