You are not logged in.

#1 2011-03-20 11:02:41

petelewis
Package Maintainer (PM)
From: Birmingham, UK
Registered: 2008-08-14
Posts: 128
Website

Using alt key in console vim.

Hi folks,

Does anyone out there have a working method for using alt-<key> mappings in vim on the console? I've read a fair amount and the consensus seems to be "tweak all these different things to find what works on your system". So, what works on Arch (on a standard PC)?

First off, I read this:
http://vimdoc.sourceforge.net/htmldoc/m … p-alt-keys

I am currently trying some vim maps like

nmap <a-s> <C-w>s

And I'm using urxvt, so have tried the following in my .Xdefaults:

URxvt*meta8:true

This stops urxvt from converting alt key presses into esc-<key> patterns, but it's not activating the vim map. (It works in gvim BTW).

Has anyone got this to work? Or is the consensus that esc-<key> patterns are the way to go, with a .vimrc adapted to accept them, e.g. as in this:
http://vim.wikia.com/wiki/Fix_meta-keys … nsert_mode

A working config would be much appreciated!

Pete.


"Cared thou not, thou would have abstained." - Xyne

Offline

#2 2011-03-20 11:44:06

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: Using alt key in console vim.

I'm a little confused; first you say console, then you say that you're using urxvt? Is the problem in both environments? Anyway, see :help key-codes.

Offline

#3 2011-03-20 11:48:36

petelewis
Package Maintainer (PM)
From: Birmingham, UK
Registered: 2008-08-14
Posts: 128
Website

Re: Using alt key in console vim.

dmz wrote:

I'm a little confused; first you say console, then you say that you're using urxvt? Is the problem in both environments?

Sorry, I meant "console" as opposed to gvim.

And yes, neither <M- or <A- keybindings work in either the console or in urxvt. But as I said, gvim is fine due to its independent handling of the alt key.

Thanks.

Update: it works in xterm, so that must be doing the 8 bit thing correctly.

Last edited by petelewis (2011-03-20 11:58:09)


"Cared thou not, thou would have abstained." - Xyne

Offline

#4 2011-03-20 12:59:29

petelewis
Package Maintainer (PM)
From: Birmingham, UK
Registered: 2008-08-14
Posts: 128
Website

Re: Using alt key in console vim.

Ugh, okay I've figured out the problem, at least. It works fine when I use a non utf-8 locale. I.e. when LANG is something like en_US.88591. But with en_US.UTF-8 it seems to not have provided enough bits (or perhaps provided too many, I'm no expert on encoding stuff).

I found this (apparently resolved) bug which I think is about the same thing:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=558725

And this explains the problem better than I can:
http://tech.groups.yahoo.com/group/vim/message/87494

So I guess using alt as alt isn't possible with UTF8...?


"Cared thou not, thou would have abstained." - Xyne

Offline

#5 2011-03-20 16:02:22

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,094

Re: Using alt key in console vim.

I use alt with vim all the time in urxvt, and I do use utf8. Havn't done anything special to neither vim nor urxvt.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#6 2011-03-20 17:05:20

petelewis
Package Maintainer (PM)
From: Birmingham, UK
Registered: 2008-08-14
Posts: 128
Website

Re: Using alt key in console vim.

Mr.Elendig wrote:

I use alt with vim all the time in urxvt, and I do use utf8. Havn't done anything special to neither vim nor urxvt.

Hmmm interesting. Can you confirm your LANG variable?


"Cared thou not, thou would have abstained." - Xyne

Offline

#7 2011-03-20 20:21:30

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,094

Re: Using alt key in console vim.

[oh@Alice][~]% echo $LANG
en_GB.utf8
[oh@Alice][~]% pacman -Q gvim rxvt-unicode-patched
gvim 7.3.138-1
rxvt-unicode-patched 9.10-1
[oh@Alice][~]% 

The patches applied to urxvt shouldn't affect it, only changes some rendering issues. (fontwidth, size hint)


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#8 2011-03-20 20:38:46

petelewis
Package Maintainer (PM)
From: Birmingham, UK
Registered: 2008-08-14
Posts: 128
Website

Re: Using alt key in console vim.

How odd. I wonder what is different.

Sorry to keep asking stuff, but can you try this in a vim in urxvt: in insert mode, hit Ctrl-v then Alt-a and tell me what appears on the screen?

I've now configured it to use the escapes instead (meta8 = false), so I get:

^[a

and I've adapted vim to read that as an alt keypress.

But if you're not using escapes it should just display a

á

The latter is what xterm still does for me, but urxvt won't, and just sits there waiting for more input.


"Cared thou not, thou would have abstained." - Xyne

Offline

#9 2011-03-20 21:19:01

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,094

Re: Using alt key in console vim.

it returns ^[a as it should.
Are you running it in screen/tmux btw? and what is your TERM set to?

Last edited by Mr.Elendig (2011-03-20 21:20:09)


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#10 2011-03-20 21:43:12

petelewis
Package Maintainer (PM)
From: Birmingham, UK
Registered: 2008-08-14
Posts: 128
Website

Re: Using alt key in console vim.

Mr.Elendig wrote:

it returns ^[a as it should.

Ah ha - okay. So you're using escapes too, rather than meta8 (this is the default, so makes sense). Yeah, I got it working doing that, but had to adapt my .vimrc to get it to acknowledge the ^[ as "alt". Didn't you, or did a simple map of e.g. <A-a> suffice?

Are you running it in screen/tmux btw? and what is your TERM set to?

Yeah, I thought that too and though I do run it in tmux usually, I've been testing it both with and without (TERM is set to screen-256color BTW) and it made no difference. Still, unless I specifically map the ^[ to alt in vim, it doesn't work. With meta8 it works so long as the locale is not UTF-8.

Guess I've got a workaround for now, but it would be nice if meta8 and utf-8 worked nicely together.

Thanks.


"Cared thou not, thou would have abstained." - Xyne

Offline

#11 2012-04-10 12:27:19

balta2ar
Member
From: Russia, Moscow
Registered: 2010-03-23
Posts: 25
Website

Re: Using alt key in console vim.

petelewis wrote:
Mr.Elendig wrote:

it returns ^[a as it should.

Ah ha - okay. So you're using escapes too, rather than meta8 (this is the default, so makes sense). Yeah, I got it working doing that, but had to adapt my .vimrc to get it to acknowledge the ^[ as "alt". Didn't you, or did a simple map of e.g. <A-a> suffice?

Are you running it in screen/tmux btw? and what is your TERM set to?

Yeah, I thought that too and though I do run it in tmux usually, I've been testing it both with and without (TERM is set to screen-256color BTW) and it made no difference. Still, unless I specifically map the ^[ to alt in vim, it doesn't work. With meta8 it works so long as the locale is not UTF-8.

Guess I've got a workaround for now, but it would be nice if meta8 and utf-8 worked nicely together.

Thanks.

Could you please show how your vimrc looks like? I have the same problem and I'm interested in your workaround.

Offline

#12 2012-05-10 09:17:59

petelewis
Package Maintainer (PM)
From: Birmingham, UK
Registered: 2008-08-14
Posts: 128
Website

Re: Using alt key in console vim.

Hmmm, it's been a while I'm afraid, so I'm not sure exactly what I changed. I don't appear to have anything special in my .vimrc, but I do have

URxvt*meta8:False

in my ~/.Xdefaults.

My full .vimrc is here, in case that helps:

http://muddygoat.org/git/vim.git/

HTH.


"Cared thou not, thou would have abstained." - Xyne

Offline

#13 2014-10-11 19:58:29

rosshadden
Member
Registered: 2014-03-06
Posts: 5

Re: Using alt key in console vim.

I know this is a couple years old, but did you ever get meta8 working with utf-8?  I have been fighting this issue for many hours, and didn't want to give up until I saw this thread.  The problem is hard to search for, and you are the first person I've found with the same issue.

The urxvt docs and the internet make it seem like enabling meta8 is a good practice, yet when enabled hitting alt "waits for more input", as you put it.

Offline

#14 2014-10-11 21:51:19

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,718
Website

Re: Using alt key in console vim.

rosshadden,

It is better to start a  new thread and make reference to the "old thread" in cases like this.
You will find that reviving old threads is frowned upon and explicitly indicated as a "you shall not do that" by Arch forum rules.

As per your specific question I'm afraid I cannot be of help.

R.

Offline

#15 2014-10-13 08:50:45

petelewis
Package Maintainer (PM)
From: Birmingham, UK
Registered: 2008-08-14
Posts: 128
Website

Re: Using alt key in console vim.

To be honest, I know it's "the rules" and all that, but in this case I found this helpful. For example, since this issue still wasn't satisfactorily solved, adding to this thread meant that an email got pinged to me (since I'd subscribed). I'd have missed it if it was a new thread.


"Cared thou not, thou would have abstained." - Xyne

Offline

Board footer

Powered by FluxBB