

If you find a better explanation please let me know. I looked at the escape sequences for plain arrow keys, Shift-arrow keys and Control-arrow keys and I decided to experiment a little in the neighboring spaces, using C-h k to figure out which key sequence is bound to what I want. You can look as an example at the values for Control-left and friends that were added when you loaded the xterm Defaults map. To do this, click on the + sign, type the key sequence, then under Action: select Send Escape Sequence and type in the escape seequence starting with [1. Go back to the profile key bindings under iTerm2 and add bindings for the following: The xterm Defaults only provided us with certain key bindings. Add Meta-arrow and Control-Meta-arrow to iTerm2 If that works, you are ready for the next step. Once you load the above code, try C-left again in paredit.

(define-key paredit-mode-map (kbd "M-[") nil) We need to turn off this behavior, which we can do by putting the following in ~/.emacs Emacs starts interpreting this sequence, but it gets an early match on ESC [ which is the same as M-[ and invokes paredit-bracket-wrap-sexp.

Interactive Lisp function in `paredit.el'.Įach time you press Control + left arrow the terminal will send the following sequence as defined above: ESC [ 1 5 D. M-[ runs the command paredit-bracket-wrap-sexp, which is an If you try C-h k C-left you will most likley see You can figure this out by trying describe key again. If this happens only in paredit mode, then the culprit is most likely the bidning of M-[. Chances are you will see [1 5D and [1 5C. Now turn on paredit mode ( M-x paredit-mode) and try C-left and C-right again. PareditĪt this point you should have C-left working outside of paredit. Note that input-decode-map is only defined starting with Emacs 23. Should you have to define your own bindings for these escape sequences you could do so with With argument ARG, do this that many times.Īs long as TERM is set to xterm the above bindings should work automatically in Emacs. Move backward until encountering the beginning of a word. runs the command backward-word, which is an interactive To verify Emacs is picking up the correct keys you can also try C-h k for Describe key followed by the key combination. Now, with paredit turned off, try C-left and C-right, which should most likely move a word at a time left and right respectively. Open up a new terminal window and then open emacs at the terminal with emacs -nw. Check Control-arrow bindings within Emacs These are not quite sufficient, but before we go any futher, let’s make sure we can get these to work in Emacs. It will also define Shift arrows and Control-Shift arrows, but we don’t care about those at the moment. This will map C-up, C-down, C-right, and C-left to send the following escape sequences: The easiest way to get started is select Load Preset… > xterm Defaults.
#Iterm2 move cursor by word series#
For the arrow key fixes though you will need to add a series of key shortcuts. While you are here verify you have Left Option and Right Option as +Esc. Select Profiles > Open Profiles… from the menu bar, or press Command-O and take a look at the default profile. You can also fix this however for Terminal.app or the original iTerm. First, I suspected that Control arrow combinations were not being sent properly by my terminal, in my case iTerm2. Today I decided to get to the bottom of this problem at any cost.
#Iterm2 move cursor by word install#
To get paredit to work properly I kept switching to Cocoa Emacs (in case you didn’t know, you can install Cocoa emacs with brew install emacs -cocoa if you are using “homebrew) ) Especially when working with ( which frequently involves the use of C-left, C-right, C-M-left, C-M-right and less frequently of M-up and M-down. One problem that has plagued me until today though has been the lack of proper Control and Meta arrow combinations when working at the terminal. I prefer to use Emacs in a full-screen terminal window. Emacs + paredit under terminal (Terminal.app, iTerm, iTerm2)
