emacs in terminal meta arrow keybindings

后端 未结 2 811
孤街浪徒
孤街浪徒 2020-12-30 11:29

I have just switched from using Emacs.app to emacs server and emacsclient in terminal mode using iterm2 as my terminal emulator. I am having some trouble with some keybindin

相关标签:
2条回答
  • 2020-12-30 11:45

    I'm answering in reply to your 'main problem solved, but new one' edit.

    I found this guy's blog post on this issue: - http://webframp.com/emacs/2013/02/22/fixing-emacs-bindings-on-the-in-iterm2/

    Basically, you can use the 'run cat' and push buttons trick to see what escape codes are getting sent by your system/terminal, then add 'define-key' lines to define M-{up,down,right,left} and also M-S-{up,down,right,left}.

    0 讨论(0)
  • 2020-12-30 12:08

    Solution 1

    Based on the info you provided here's one thing you can try. You tell emacs to map those escape sequences to the proper key sequences:

    (add-hook 'term-setup-hook
      '(lambda ()
         (define-key function-key-map "\e[1;9A" [M-up])
         (define-key function-key-map "\e[1;9B" [M-down])
         (define-key function-key-map "\e[1;9C" [M-right])
         (define-key function-key-map "\e[1;9D" [M-left])))
    

    Solution 2

    I also found another possible solution with a little googling: redefine the iTerm bindings instead to match what emacs is looking for.

    http://offbytwo.com/2012/01/15/emacs-plus-paredit-under-terminal.html

    Quote from the above page:

    Go back to the profile key bindings under iTerm2 and add bindings for the following:

    M-up      : Esc-[1;4A
    M-down    : Esc-[1;4B
    M-right   : Esc-[1;4C
    M-left    : Esc-[1;4D
    
    0 讨论(0)
提交回复
热议问题