mapping - Alt key shortcuts not working on gnome terminal with Vim -


i'm running vim on gnome terminal. alt key mappings not working.
for example (this example):

:imap <a-i> <esc> 

it works fine in gvim. when run same command vim in gnome terminal doesn't work.
so think problem terminal, right?
how can fix it?

thanks

edit: have windows 7 installed on same machine, , windows terminal works fine too.

the problem

there 2 ways terminal emulator send alt key (usually called meta key actual terminals didn't have alt). can either send 8 bit characters , set high bit when alt used, or can use escape sequences, sending alt-a <esc>a. vim expects see 8 bit encoding rather escape sequence.

some terminal emulators such xterm can set use either mode, gnome terminal doesn't offer such setting. honest in these days of unicode editing, 8-bit encoding not such idea anyway. escape sequences not problem free either; offer no way of distinguishing between <esc>j meaning alt-j vs pressing esc followed j.

in earlier terminal use, typing escj way send meta on keyboard without meta key, doesn't fit vi's use of esc leave insert mode.

the solution

it possible work around configuring vim map escape sequences alt combinations.

add .vimrc:

let c='a' while c <= 'z'   exec "set <a-".c.">=\e".c   exec "imap \e".c." <a-".c.">"   let c = nr2char(1+char2nr(c)) endw  set timeout ttimeoutlen=50 

alt-letter recognised vi in terminal gvim. timeout settings used work around ambiguity escape sequences. esc , j sent within 50ms mapped <a-j>, greater 50ms count separate keys. should enough time distinguish between meta encoding , hitting 2 keys.

if don't having timout set, times out other mapped key sequences (after second default), can use ttimeout instead. ttimeout applies key codes , not other mappings.

set ttimeout ttimeoutlen=50 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -