19

I would like to use Cmd+/ instead of Alt+/ to move the cursor word by word in Mac OSX (A Cocoa thing I guess).

Is it possible to change that?

And by the same token, I would like to move the cursor to the beginning and end of the line by using Alt+/ instead of Cmd+/.

Can it be done?

5 Answers 5

12

One option would be to create ~/Library/KeyBindings/ and save this as DefaultKeyBinding.dict:

{
    "@\UF702" = moveWordBackward:;
    "@\UF703" = moveWordForward:;
    "~\UF702" = moveToBeginningOfLine:;
    "~\UF703" = moveToEndOfLine:;
    "~$\UF702" = moveToBeginningOfLineAndModifySelection:;
    "~$\UF703" = moveToEndOfLineAndModifySelection:;
}

You can't change ⇧⌘← or ⇧⌘→ though. And it doesn't work in some text views or Xcode or Firefox.

Using KeyRemap4MacBook, you could add this to private.xml:

<autogen>--KeyToKey-- KeyCode::CURSOR_LEFT, VK_OPTION | ModifierFlag::NONE, KeyCode::CURSOR_LEFT, VK_COMMAND</autogen>
<autogen>--KeyToKey-- KeyCode::CURSOR_RIGHT, VK_OPTION | ModifierFlag::NONE, KeyCode::CURSOR_RIGHT, VK_COMMAND</autogen>
<autogen>--KeyToKey-- KeyCode::CURSOR_LEFT, VK_SHIFT | VK_OPTION | ModifierFlag::NONE, KeyCode::CURSOR_LEFT, VK_SHIFT | VK_COMMAND</autogen>
<autogen>--KeyToKey-- KeyCode::CURSOR_RIGHT, VK_SHIFT | VK_OPTION | ModifierFlag::NONE, KeyCode::CURSOR_RIGHT, VK_SHIFT | VK_COMMAND</autogen>
<autogen>--KeyToKey-- KeyCode::CURSOR_LEFT, VK_COMMAND | ModifierFlag::NONE, KeyCode::CURSOR_LEFT, VK_OPTION</autogen>
<autogen>--KeyToKey-- KeyCode::CURSOR_RIGHT, VK_COMMAND | ModifierFlag::NONE, KeyCode::CURSOR_RIGHT, VK_OPTION</autogen>
<autogen>--KeyToKey-- KeyCode::CURSOR_LEFT, VK_COMMAND | VK_SHIFT | ModifierFlag::NONE, KeyCode::CURSOR_LEFT, VK_OPTION | VK_SHIFT</autogen>
<autogen>--KeyToKey-- KeyCode::CURSOR_RIGHT, VK_COMMAND | VK_SHIFT | ModifierFlag::NONE, KeyCode::CURSOR_RIGHT, VK_OPTION | VK_SHIFT</autogen>

It would make going back with ⌘← and changing tabs with ⇧⌘← stop working though.

See the source for the key code constants and predefined settings.

1
  • The first option is best because it doesn't overwrite the other keybindings. Also this page is a great reference for customizing your DefaultKeyBinding.dict
    – aaaaaa
    Commented Feb 17, 2016 at 16:36
3

Yes. Using Keyboard Maestro, I just created two new macros.

The first has a "hot key trigger" of < command >< left arrow > and does a "type a keystroke" of < option >< left arrow >

The second is the reverse, a "hot key trigger" of < option >< left arrow > and does a "type a keystroke" of < command >< left arrow >. And it does work.

You could then add 2 more macros for the right direction.

The way I wrote them as a quick test they are system wide but they can be limited to specific sets of applications.

While Keyboard Maestro is not free, it does have time limited demo.

3
  • Thanks for the suggestion. I would prefer a free method. I bet there's some way to dig in the settings/files of the system somehow...
    – trusktr
    Commented Feb 18, 2013 at 2:02
  • +1 This is the best option for me on macOS Sierra. I used it to remap word selection and word "hopping" to match the Windows combinations.
    – Sébastien
    Commented Dec 1, 2016 at 14:25
  • This works pretty much perfectly for me. Keyboard Maestro is exceptionally powerful and can be used for tons of automation. Commented Mar 8, 2019 at 1:42
1

I would recommend karabiner to you. It's a powerful system plugin to remap keys and key combinations. You can map whatever key combos you want to whatever in your mind. Please check it out and you will fall in love with it

3
  • How exactly would Karabiner need to be configured to accomplish the task described in the question?
    – nohillside
    Commented Apr 19, 2016 at 18:36
  • I like Karabiner. I guess I'd have to look at the source code to find out how it works.
    – trusktr
    Commented Apr 20, 2016 at 0:33
  • just set the cmd + left as the trigger for karabiner to send the event of alt + left. And you can even restrict the remap of the keys within certain applications or windows
    – hzh
    Commented Aug 28, 2016 at 4:59
1

I've used KeyBindingsEditor (free) to edit the DefaultKeyBindings.dict and it works great (even in Firefox and XCode).

cursor settings with KeyBindingsEditor

Leaving the thumb button on the ⌘ key while cruising the text cursor works so much better -- it should be the default!

3
  • I haven't tried this in Yosemite. Do you know if still works?
    – trusktr
    Commented Nov 9, 2014 at 3:33
  • It does!! :) :) :)
    – trusktr
    Commented Nov 9, 2014 at 3:43
  • Does not seem to work on Sierra - the app window does not show up :( Commented Jul 26, 2017 at 23:52
-1

word-by-word: option+/

go to start/end: command+/

2
  • 1
    Yes the OP knows this - they want to know how to change it.
    – mmmmmm
    Commented Nov 2, 2022 at 14:57
  • thanks for them!! Commented Dec 12, 2022 at 19:22

You must log in to answer this question.

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