Is there a way to make alt-f and alt-b jump word forward and backward instead of printing ƒ and ∫ on Mac?

后端 未结 7 1552
渐次进展
渐次进展 2021-01-31 02:03

I understand that Mac has some Emacs keybindings enabled by default (e.g. Ctrl+A move to beginning of line etc.). If I open TextEdit for example I can navi

相关标签:
7条回答
  • 2021-01-31 02:37

    On iTerm2 3.0.15, go to:

    Preferences -> Default -> Keys tab ->"Left option() key acts as:" 
    

    and change the value to:

    +Esc
    
    0 讨论(0)
  • 2021-01-31 02:38

    I'm a little confused if you're talking about the keys (within different apps on OS X) or specifically Emacs. On OS X the standard keys you would use to jump between words is:

    option/alt + Left Arrow or Right Arrow

    If it's specific to Emacs for OS X:

    For Terminal.app, starting from Snow Leopard: Go to Preferences > Settings > Keyboard > Use option as meta key.

    For iTerm: Go to Manage Profiles > Keyboard profiles > (your profile) > Option Key as…

    If you want to use Option key for both international characters and Meta key in Emacs, see info below for iTerm 0.10.x patch and/or binary.

    Alt-b and Alt-f for navigating by word also works for your shell now.


    UPDATE: The link the original website providing the patch is no longer online, however I was able to retrieve the cached information from the archive.org:

    OSX + terminal + Meta key + national characters

    Quite a mix, right? If you’re user of one of those keyboard layouts that have hidden some non-ISO1 characters under Option-key shortcuts and you use command line – read on, I might have a treat for you.

    As it stands today, if you’re OSX user, and would like to use your Option (Alt) keys for both national characters and Meta-* shortcuts, you’re in for an unpleasant surprise – you can’t. It’s one or the other: both iTerm and Terminal.app allow you to flip between Option keys role, but neither of them allows you to use Option for both. Under Linux, it’s customary to use left Alt for Meta-* and right Alt for any national characters you might require. Same goes for Windows. Of course you can just train yourself in using ESC key in a prefix manner, but that’s avoiding the real problem.

    Getting annoyed by this state of things, and faced with some Emacs usage, I decided to take advantage of the fact that iTerm is opensource software, and see if I can make a tiny change, to cater for my needs. Surely enough, after ~25 minutes I got a trivial patch: just changed the mask that iTerm uses for detecting that Option key is pressed down. It took few hours and 5 chapters of Cocoa book, to turn that into fully-fledged option in Keyboard Profiles section of iTerm. This was my first foray into lands of Objective C; while I came back victorious, I don’t see myself writing anything bigger in Objective C in nearest future.

    Here’s the meat: ( https://sourceforge.net/p/iterm/patches/44/ )

    • “right Option is Normal” patch;
    • full patch allows you to pick which keys should be treated as Meta (both, only left, only right);

    The patches were made against 0.10.x branch, at revision 1871.

    Once you have the binary, launch it and go to Bookmarks > Manage profiles > Keyboard profiles. If you select a keyboard profile, you should see a new dropdown at the bottom of the keybindings list.

    The options should be pretty much self-explanatory. The configuration shown above is the one I’m using — this way I get all Meta-* shortcuts with my left Option key, and all Polish characters with right Option key. Which is the way it Should Be™ :)

    I haven’t heard from iTerm authors yet, so I have no idea whether this patch is going to merged upstream or not. I’ve been using my patched version for almost week and a half now, and nothing major exploded. Yes, iTerm is slower to redraw the screen on larger terminals (say, 130×80), but there are certain features (like 256 colors support) that make up for that.

    more info: http://www.emacswiki.org/emacs/EmacsForMacOS

    0 讨论(0)
  • 2021-01-31 02:39

    You should use KeyRemap4MacBook. In the Emacs Mode section, you will find numerous options to use the Option key as Meta including Option+BF to Option+Left/Right.

    However, if you're a hardcore Dvorak user like myself who wants to use key bindings such as M-b and M-f using the original Dvorak layout, there's a problem. You can only "move backward/forward one word" in QWERTY layout. I use version 8.4.0 so I don't know about the latest version for Mavericks.

    0 讨论(0)
  • 2021-01-31 02:47

    Solved this at the OS level as follows,

    ⟶ System preferences
    ⟶ Keyboard
    ⟶ Input Sources Tab
    + at bottom left
    Others in the left panel
    ⟶ add and select Unicode Hex Input from right panel

     ✓  Mac no longer prints anything on alt+letter|number
     ✓  enter unicode characters via alt+[code]
     ✅ the OS does not grab alt key shortcuts!

    0 讨论(0)
  • 2021-01-31 02:51

    If you want to re-enable them for the terminal

    Terminal -> Preferences -> Keyboard

    Check 'Use Option as Meta key'

    0 讨论(0)
  • 2021-01-31 02:53

    Maybe one of these helps? (I don't use OSX myself, so I can't test anything).

    • http://blog.sensible.io/2012/10/19/mac-os-x-emacs-style-keybindings-everywhere.html
    • http://aufflick.com/blog/2006/01/10/emacs-keybindings-everywhere

    Summary from first URL:

    Create file ~/Library/Keybindings/DefaultKeyBinding.dict with the following content and restart all apps.

    { "~d" = "deleteWordForward:"; "^w" = "deleteWordBackward:"; "~f" = "moveWordForward:"; "~b" = "moveWordBackward:"; }

    0 讨论(0)
提交回复
热议问题