CuaModeTerminalProblems

Cua-mode on a Linux console or terminal

Once you get used to this setup, using Emacs on the GNU/Linux console or in a terminal can be a shock, since Shift-movement doesn’t work. The console doesn’t send different escape sequences for Shift-movement and plain movement. The terminal does send different escape sequences, but Emacs doesn’t interpret them. To fix this, first make the console send the same sequences for Shift-movement as a terminal. Put this in ~/.keymap:

 keycode 103 = Up
  shift   keycode 103 = F49
 keycode 105 = Left
  shift   keycode 105 = F51
 keycode 106 = Right
  shift   keycode 106 = F52
 keycode 108 = Down
  shift   keycode 108 = F50
 string F49 = "\033O2A"
 string F50 = "\033O2B"
 string F51 = "\033O2D"
 string F52 = "\033O2C"

A more complete ~/.keymap version, with Shift|Control+Shift-movement and Shift|Control+Shift-Home|End:

 keycode 103 = Up
  Shift keycode 103 = F49
 keycode 108 = Down
  Shift keycode 108 = F50
 keycode 106 = Right
  Shift keycode 106 = F51
  Control keycode 106 = F53
  Control Shift keycode 106 = F55
 keycode 105 = Left
  Shift keycode 105 = F52
  Control keycode 105 = F54
  Control Shift keycode 105 = F56
 keycode 102 = Find
  Shift keycode 102 = F57
  Control keycode 102 = F59
  Control Shift keycode 102 = F61
 keycode 107 = Select
  Shift keycode 107 = F58
  Control keycode 107 = F60
  Control Shift keycode 107 = F62
 string F49 = "\033O2A"
 string F50 = "\033O2B"
 string F51 = "\033O2C"
 string F52 = "\033O2D"
 string F53 = "\033O5C"
 string F54 = "\033O5D"
 string F55 = "\033O6C"
 string F56 = "\033O6D"
 string F57 = "\033O2H"
 string F58 = "\033O2F"
 string F59 = "\033O5H"
 string F60 = "\033O5F"
 string F61 = "\033O6H"
 string F62 = "\033O6F"

To load the keymap, add the following to your shell’s startup file:

 if [ "$TERM" = "linux" ] ; then
    loadkeys -q .keymap
 fi

Finally, to make Emacs interpret the keys, add the following to your .emacs:

 ;; Make shifted direction keys work on the Linux console or in an xterm
 (when (member (getenv "TERM") '("linux" "xterm"))
   (dolist (prefix '("\eO" "\eO1;" "\e[1;"))
     (dolist (m '(("2" . "S-") ("3" . "M-") ("4" . "S-M-") ("5" . "C-")
                  ("6" . "S-C-") ("7" . "C-M-") ("8" . "S-C-M-")))
       (dolist (k '(("A" . "<up>") ("B" . "<down>") ("C" . "<right>")
                    ("D" . "<left>") ("H" . "<home>") ("F" . "<end>")))
         (define-key function-key-map
                     (concat prefix (car m) (car k))
                     (read-kbd-macro (concat (cdr m) (cdr k))))))))

Now you can select text the same way in X11, the console, or a terminal (assuming your terminal doesn’t intercept Shift-movement for something else, like Konsole does).

Note: I am using the complete version without problems outside X. But I couldn’t make it work on xterm with ‘emacs -nw’. But (again), if you are using X, why use ‘-nw’? :) – DeDaLu Note2: If you just struggle arround with the <up>-key you may find this helpfull: http://forums.vandyke.com/showthread.php?t=5645&page=2


CategoryKeys CategoryRegion