mess-up of arrow keys in emacs is solved. Awesome!
I am so excited now.
It is so awesome that the arrow key problem in emacs is solved. The problem is that while I started up some file with emacs, the arrow key will lose its function, and while I press those arrow key, some funny characters like "A", "B", etc will appear on the screen. INitially the problem occured to vim. After surfing internet for a while, I got the answer for vim, it is due to keyboard mapping problem. For the solution, please refer to previous post. Then, I started to work on the emacs keyboard problem. Although I have some idea that it is due to keyboard mapping problem, but still don't know where I should start, since I only know some basic stuff on emacs, like basic commands, no other further knowledge. So I set a direction to solve the problem: (1) To know what command is to bind a key. (2) what key should be bined.
After some test, finally the answer is to put below lines into .emacs.
-------------------------------------------
(global-set-key "^[OC" 'forward-char)
(global-set-key "^[OD" 'backward-char)
(global-set-key "^[OA" 'previous-line)
(global-set-key "^[OB" 'next-line)
-------------------------------------------
It should be pointed out that ^[OC should be braced with "" instead of square bracket which doesn't work as tested.
note that "^[" should be input by (ctrl+v) +[esc], rather than just copy them from screen here.
I got these inspiration from the links below, I really appreciate those people who have given me so much help anomyously.
http://www.xahlee.org/emacs/keyboard_shortcuts.html
Here are some convenient keyboard shortcuts i use, as a example of what type of keyboard shortcuts one can add to enhance productivity.
; keyboard alias for arrow keys
; with meta down,
; keys under the right hand home position become cursor keys
; Dvorak QWERTY
; c i
; htn jkl
(global-set-key "\M-h" 'backward-char) ; was mark-paragraph
(global-set-key "\M-n" 'forward-char) ; was not defined
(global-set-key "\M-c" 'previous-line) ; was capitalize-word
(global-set-key "\M-t" 'next-line) ; was transpose-words
http://gdfan.twbbs.org/blog/2005/09/21/328
http://www.vim.org/tips/tip.php?tip_id=550 (original link)
This doesn't really work very well for me on SunOS -- I have the same problem but :set term=cons25 just gives me OC everywhere before each character until I redraw. Weird.
But, :set term=ansi works great, and the arrow keys work.
A better solution is to, while in vi, type in insert mode [ctrl-v][arrow up] and see what you get.
Then, in your .vimrc, add the lines
set t_ku=[ctrl-v][esc]OA # or whatever you saw
so it ends up looking something like
set t_ku=^[OA
set t_kd=^[OB
set t_kr=^[OC
set t_kl=^[OD
(though you want REAL escape chars instead of ^[.)
No comments:
Post a Comment