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?

@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. ...
– UtkuOct 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.
– UtkuOct 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.
– UtkuOct 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
– klanomathOct 3 '15 at 18:08

1 Answer
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.)

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

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

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.

@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.
– 0942v8653Oct 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).
– 0942v8653Oct 3 '15 at 19:44