Ctrl-left and Ctrl-right in bash and Emacs

Sometimes the small things make a big difference. I noticed that the control-left and control-right keys weren’t working in bash or Emacs on my FreeBSD box accessed over X11.app on OS X. Easily fixed.

.inputrc

"\e[1;5C": forward-word     # Ctrl+right  => forward word
"\e[1;5D": backward-word    # Ctrl+left   => backward word

.emacs

(global-set-key "\M-[1;5C"    'forward-word)      ; Ctrl+right   => forward word
(global-set-key "\M-[1;5D"    'backward-word)     ; Ctrl+left    => backward word

15 thoughts on “Ctrl-left and Ctrl-right in bash and Emacs

  1. Words cannot explain how useful this is for someone struggling to get gnome-terminal behave nicely with emacs!

  2. Also, typing Ctrl-V followed by the key combination (say Ctrl-up arrow) at the shell prompt (in bash) reveals the code.

  3. for my mac, if fixed the arrow right left problem by
    “\e[5C”: forward-word # Ctrl+right => forward word
    “\e[5D”: backward-word # Ctrl+left => backward word

    Things are alright now 🙂

    Thanks for your help

  4. Thank you soo much. Spent like half an hour trying to get this to work in emacs.

  5. Pingback: C- in MacOSX’s Terminal.app :: nklein software

  6. On OSX 10.6 the Spaces feature can claim the control-arrow keys.
    That can be changed in the Expose and spaces settings.

  7. Also make sure in OSX that System Preferences>Keyboard>Shortcuts does not have a binding for Ctl-left / Ctl-right arrow (which appears to capture the keystrokes even Expose/Mission control have been turned off).

Leave a Reply

Your email address will not be published. Required fields are marked *