Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to mapping Alt-hjkl in Insert mode?

Tags:

vim

vi

before describing my problem, I'd list the env. applications here:

OS:linux 2.6.37-ARCH  (archlinux i686)
vim: 7.2.436
Terminal emulator: urxvt (with 256colors patch)

kent$ echo $TERM
rxvt-256color

screen: Screen version 4.00.03 (FAU) 23-Oct-06

I run vim in terminal. I want to move cursor in INSERT mode by pressing ALT-hjkl, after the cursor moved, stay in INSERT mode, so that I could continue typing words.

articles I found:

http://vim.wikia.com/wiki/Mapping_fast_keycodes_in_terminal_Vim

http://vim.wikia.com/wiki/Get_Alt_key_to_work_in_terminal

what I tried:

in .vimrc do a keyCode mapping with ttimeoutlen=50 like this: ( only alt-j mapping was pasted as example):

set timeout ttimeoutlen=50
set <F13>=^[j  "ctrl-v alt-j
imap <F13> <down>

with this conf, moving cursor in INSERT mode was ok. If I press <ESC> and j. Vim brings me back to insert Mode. I don't know why the ttimeoutlen=50 didn't work.

also tried:

set timeout ttimeoutlen=50
set <M-j>=^[j

With this setting, when I pressed ALT-j, a "e" with an accent mark was typed.

Can you guys give me any hints how should I map the ALT-hjkl in terminal ?

Thanks in advance

Kent

like image 935
Kent Avatar asked Mar 21 '11 15:03

Kent


1 Answers

It's easier to map what your key combination does. Alt+something generally results in a character, differently from Ctrl+something.

For example, on my Mac Alt plus hjkl generates ˙∆˚¬. So:

imap ˙ <Left>
imap ∆ <Down>
imap ˚ <Up>
imap ¬ <Right>

would do it.

like image 109
sidyll Avatar answered Oct 14 '22 05:10

sidyll