Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>The problem</h1> <p>There are two ways for a terminal emulator to send an <kbd>Alt</kbd> key (usually called a Meta key as actual terminals didn't have Alt). It can either send 8 bit characters and set the high bit when Alt is used, or it can use escape sequences, sending <kbd>Alt-a</kbd> as <code>&lt;Esc&gt;a</code>. Vim expects to see the 8 bit encoding rather than the escape sequence.</p> <p>Some terminal emulators such as <em>xterm</em> can be set to use either mode, but <em>Gnome terminal</em> doesn't offer any such setting. To be honest in these days of Unicode editing, the 8-bit encoding is not such a good idea anyway. But escape sequences are not problem free either; they offer no way of distinguishing between <code>&lt;Esc&gt;j</code> meaning <kbd>Alt-j</kbd> vs pressing <kbd>Esc</kbd> followed by <kbd>j</kbd>.</p> <p>In earlier terminal use, typing <kbd>Esc</kbd><kbd>j</kbd> was another way to send a Meta on a keyboard without a <kbd>Meta</kbd> key, but this doesn't fit well with vi's use of Esc to leave <em>insert</em> mode.</p> <h1>The solution</h1> <p>It is possible to work around this by configuring vim to map the escape sequences to their Alt combinations.</p> <p>Add this to your .vimrc:</p> <pre><code>let c='a' while c &lt;= 'z' exec "set &lt;A-".c."&gt;=\e".c exec "imap \e".c." &lt;A-".c."&gt;" let c = nr2char(1+char2nr(c)) endw set timeout ttimeoutlen=50 </code></pre> <p>Alt-letter will now be recognised by vi in a terminal as well as by gvim. The <code>timeout</code> settings are used to work around the ambiguity with escape sequences. <kbd>Esc</kbd> and <kbd>j</kbd> sent within 50ms will be mapped to <code>&lt;A-j&gt;</code>, greater than 50ms will count as separate keys. That should be enough time to distinguish between Meta encoding and hitting two keys.</p> <p>If you don't like having timout set, which times out for other mapped key sequences (after a second by default), then you can use <code>ttimeout</code> instead. ttimeout applies only to key codes and not other mappings.</p> <pre><code>set ttimeout ttimeoutlen=50 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload