Wikia

Vim Tips Wiki

Changes: Get Alt key to work in terminal

Edit

Back to page

(minor clean)
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
xterm, by default, sets eightBitInput to true, meaning that the eighth bit is set for metacharacters (combinations with the Alt key, for instance). Not all terminals have this feature enabled by default, and therefore work differently (they send an ESC before the character key).
+
Xterm, by default, sets eightBitInput to true, meaning that the eighth bit is set for meta characters (combinations with the Alt key, for instance). Not all terminals have this feature enabled by default, and therefore work differently (they send an Esc before the character key).
   
So for the xterm, with enables the eight bit, you can just do something like,
+
So for the xterm, with enables the eight bit, you can just do something like:
 
<pre>
 
<pre>
 
map <m-a> ggVG
 
map <m-a> ggVG
 
</pre>
 
</pre>
   
However, with a terminal that's in 7 bit mode, you have to do this:
+
However, with a terminal that is in 7 bit mode, you have to do this:
 
 
<pre>
 
<pre>
 
set <m-a> = ^[a
 
set <m-a> = ^[a
 
map <m-a> ggVG
 
map <m-a> ggVG
" the ^[ is an ESC char that comes before the 'a'
+
" the ^[ is an Esc char that comes before the 'a'
 
</pre>
 
</pre>
   
 
My tip is to just set all terminals to work in 8 bit mode. Here are two examples:
 
My tip is to just set all terminals to work in 8 bit mode. Here are two examples:
 
 
<pre>
 
<pre>
 
Eterm -8
 
Eterm -8
 
rxvt --meta8
 
rxvt --meta8
 
</pre>
 
</pre>
  +
  +
==See also==
  +
*[[VimTip738|Fix meta-keys that break out of Insert mode]]
   
 
==Comments==
 
==Comments==
 
Also, these are the settings I use in my /etc/inputrc:
 
Also, these are the settings I use in my /etc/inputrc:
 
 
<pre>
 
<pre>
 
set meta-flag on
 
set meta-flag on
Line 46: Line 47:
   
 
----
 
----
See also [[VimTip738|VimTip738:fix META-keys on Unix terminals]].
+
The only version that works for me (Vim 7.1 on Ubuntu 8.04 x86, connected to by Putty 0.60 on Windows XP 32bit):
 
----
 
the only version that works for me: (Vim 7.1 on Ubuntu 8.04 x86, connected to by Putty 0.60 on Windows XP 32bit)
 
 
line in .vimrc to map for example "Alt-RightArrowKey" to "switch to next open file":
 
   
  +
Line in .vimrc to map for example "Alt-RightArrowKey" to "switch to next open file":
 
<pre>
 
<pre>
:map ^[<Right> :hide bn<CR>
+
:map ^[<Right> :hide bn<CR>
 
</pre>
 
</pre>
   
'''crucial''': to get the ^[<Right> press in insert mode Control-V then Alt-x, remove the x, insert the seven Characters "<Right>"
+
'''Crucial''': to get the ^[<Right> press in insert mode Control-V then Alt-x, remove the x, insert the seven Characters "<Right>".
  +
  +
See {{help|key-notation}} for more key special names like "<Right>".
   
more key special names like "<Right>": http://www.vim.org/htmldoc/intro.html#key-notation
+
''klaus thorn''
   
''klaus thorn, klaus at trillke.net''
 
 
----
 
----

Revision as of 03:11, May 18, 2009

Tip 1129 Printable Monobook Previous Next

created February 12, 2006 · complexity basic · author Matt Zyzik · version 5.7


Xterm, by default, sets eightBitInput to true, meaning that the eighth bit is set for meta characters (combinations with the Alt key, for instance). Not all terminals have this feature enabled by default, and therefore work differently (they send an Esc before the character key).

So for the xterm, with enables the eight bit, you can just do something like:

map <m-a> ggVG

However, with a terminal that is in 7 bit mode, you have to do this:

set <m-a> = ^[a
map <m-a> ggVG
" the ^[ is an Esc char that comes before the 'a'

My tip is to just set all terminals to work in 8 bit mode. Here are two examples:

Eterm -8
rxvt --meta8

See also

Comments

Also, these are the settings I use in my /etc/inputrc:

set meta-flag on
set input-meta on
set convert-meta on
set output-meta on

These are so that alt keys like <m-b>, <m-f>, <m-d> will work well in shell.


The only version that works for me (Vim 7.1 on Ubuntu 8.04 x86, connected to by Putty 0.60 on Windows XP 32bit):

Line in .vimrc to map for example "Alt-RightArrowKey" to "switch to next open file":

:map ^[<Right> :hide bn<CR>

Crucial: to get the ^[<Right> press in insert mode Control-V then Alt-x, remove the x, insert the seven Characters "<Right>".

See :help key-notation for more key special names like "<Right>".

klaus thorn


Around Wikia's network

Random Wiki