My mappings which contain Alt aren't working in vim when using in urxvt. They work fine in gvim. An example of such mapping

map <silent> <A-h> <C-w><

In insert mode when I type Alt-h, only h is printed. How do I need to configure urxvt such that mappings containing Alt work in vim? I am using Ubuntu.

Oops I set my modifier as super in urxvt. That's why none of the solutions were working for me. Make sure that you set the modifier as Alt to get the solutions proposed to work.


3 Answers 3


When you make an <A-x> mapping in Vim when x is a printable character (i.e., not a cursor or arrow key), it tells Vim to expect that character with the 8th/high bit set (aka, add 128 to the ASCII value).

In your example, <A-h> means Vim will trigger the mapping when you type è. The ASCII value of h is 104 (binary 01101000) and when you set the 8th bit of that number, you get è's ASCII value of 232 (binary 11101000).

What happens in urxvt and many other terminals is that the Alt key is set to send the character typed prefixed with the Escape character instead of "adding 128". In this case, Vim seed <Esc>h instead of è, so the mapping isn't triggered.

This leaves you two options: re-configure your terminal to do something different with the Alt modifier or add more mappings to Vim with <Esc>x in addition to <A-x>.

  • 1
    Just pointing out that you need to set Alt as the modifier in urxvt for this solution to work
    – ma08
    May 1, 2015 at 9:38

If you need to enter non-ASCII text, try changing your mappings in vim from <A-x> to <Esc>x.

If you enter only ASCII text, you may try launching urxvt with --meta8 option, and in vim set termencoding=latin1.

You may also try other solutions from:


  • See the vim-alt-mappings for automating the Esc maps and an explanation of what will break if you use it (why this is a bad idea).
    – idbrii
    Apr 30, 2015 at 22:27
  • setting the termencoding to latin1 is breaking my powerline. Weird characters are appearing.
    – ma08
    May 1, 2015 at 9:11

I am shamelessly posting the answer given by u/jbaumy93 on reddit.

Here is what I am using now,

In ~/.Xresources I am not setting URxvt.meta8: true as the encoding is breaking when I set it. If I use set termencoding=latin, it is messing up with powerline characters. I decided to use the Esc mappings as @graywh has posted and using the answer linked above to do so.

Also make sure that the modifier is set as Alt in urxvt. I have been using super as the modifier and none of the posted solutions worked.

Here is the snippet from my vimrc

nnoremap <silent> <A-h> <C-w><
nnoremap <silent> <A-k> <C-w>-
nnoremap <silent> <A-j> <C-w>+
nnoremap <silent> <A-l> <C-w>>
function! Altmap(char)
  if has('gui_running') | return ' <A-'.a:char.'> ' | else | return ' <Esc>'.a:char.' '|endif
if $TERM == 'rxvt-unicode-256color'&&!has('gui_running')
  set ttimeoutlen=10
  augroup FastEscape
    autocmd InsertEnter * set timeoutlen=400
    autocmd InsertLeave * set timeoutlen=2000
  augroup END
  execute 'nnoremap <silent>'.Altmap('h').'<C-w><'
  execute 'nnoremap <silent>'.Altmap('k').'<C-w>-'
  execute 'nnoremap <silent>'.Altmap('j').'<C-w>+'
  execute 'nnoremap <silent>'.Altmap('l').'<C-w>>'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .