Here's Piet Delport's excellent explanation for why mapping the meta
(alt) key, like this:
:map <M-g> /foo<CR>cwbar<Esc>
sometimes doesn't work. Thanks!
--Jeff
----- Forwarded message from Piet Delport <[EMAIL PROTECTED]> -----
Date: Fri, 24 Aug 2001 20:59:58 +0200
From: Piet Delport <[EMAIL PROTECTED]>
Subject: Re: Using mapping to augment hjkl
On Fri, 24 Aug 2001 at 12:24:45 +1000, Jeff Turner wrote:
> Hello,
>
> The "vim way of life" thread made me appreciate just how cool hjkl movement
> is. But as home keys go, their functionality is quite limited. hjkl moves
> around; HJKL does various maybe-useful things (I only ever use J
> frequently), and that's it.
>
> So I'd like to map <M-h> and <M-l> to '(' and ')' respectively, to move
> between sentences. In ':help map-examples', there's the following
> example:
>
>:map <M-g> /foo<CR>cwbar<Esc>
>
> If I enter that, it doesn't work. If I type ":map", I see:
>
> � /foo<CR>cwbar<Esc>
>
> Erm. What's that odd � doing there?
>
> I'm using 6.0ag. Removing my .vimrc makes no difference.
Tried the mapping, and it works fine under gvim here. It also shows up as:
� /foo<CR>cwbar<Esc>
when i do a ":map", BTW.
I think it's because 'g' with the 8th (or meta) bit set is '�', and under the
GUI, pressing Alt-g results in a said '�' character being generated.
However, under console vim (which is what you're using?), the mapping didn't
work. I think this is because my terminal is set up to handle Alt-<foo> by
prefixing <foo> with an escape character, and not by setting the 8th bit of
<foo>.
So on hunch i tried:
:map <Esc>g /foo<CR>cwbar<Esc>
and it works. :)
So, to summarise: On both vim and gvim, ":map <M-G> ..." results in � (or, g
with the 8th bit set) being mapped. This doesn't work under console vim if
your terminal generates an "g" sequence when you press Alt-g.
Solution 1:
Put something like the following in your .vimrc:
if has('gui_running')
map <M-g> /foo<CR>cwbar<Esc>
else
map <Esc>g /foo<CR>cwbar<Esc>
endif
to conditionally map <M-g> or <Esc>g depending on whether you're in the GUI or
not.
Solution 2:
Get your terminal to handle Alt-<foo> keypresses by setting the 8th bit,
instead of prefixing an escape character.
I got this working by for rxvt by adding:
Rxvt*meta8: true
to my ~/.Xdefaults. This might break other programs though. (It broke mutt
here, which expects escape-prefixed characters for its Alt- commands. I could
fix this by setting meta_key=yes in my .muttrc, but am getting sidetracked...)
HTH,
--
Piet Delport <[EMAIL PROTECTED]>
Today's subliminal thought is:
----- End forwarded message -----