Strange behavior with Key Maps

0 views
Skip to first unread message

Samer

unread,
Dec 5, 2008, 12:45:30 PM12/5/08
to vim_use
Hello,

I have mappings that look like this in my ftplugin/java.vim

imap <buffer> <S-C-m> <Esc>:JavaImport<CR>a
map <buffer> <S-C-m> <Esc>:JavaImport<CR>

The first mapping works fine, but the second one inexplicably leads to
a remapping of <CR>! To see that, open vim (I have vim7.2) and then
type :map <buffer> <S-C-m> <Esc>:JavaImport<CR> then do :map, you
should see this:

<CR> @<Esc>:JavaImport<CR>

This doesn't happen with imap at all.

What am I doing wrong?

Samer

Tony Mechelynck

unread,
Dec 5, 2008, 7:33:05 PM12/5/08
to vim...@googlegroups.com

I see <CR> as the {lhs} in the listings produced by both ":map" (for
Normal mode etc.) and ":map!" (for Insert mode etc.)

IMHO what you're doing wrong is not realizing that for Vim (and for
ASCII where Vim takes it from),

- Ctrl-M is the carriage-return character
- So is <Enter>
- Ctrl-letter ignores case (i.e., Ctrl-M and Ctrl-m are the same, and so
are Ctrl-A and Ctrl-a, Ctrl-B and Ctrl-b, etc., until Ctrl-Z and Ctrl-z).

If you want to assign a mapping to a single key (not a key sequence), I
recommend an F key (with the exception of F1 which is Help, and of F10
which on some systems is Menu), with or without Shift (and even Shift-F1
and Shift-F10 are possible). In my experience these are the keys which
are neither yet used by Vim for its own purposes, nor hidden from the
program by most OSes Vim runs on (e.g. on the system where I'm now,
Ctrl-Fn and Alt-Fn are used by the window manager, so they never reach
the application -- any application).


Best regards,
Tony.
--
Honesty pays, but it doesn't seem to pay enough to suit some people.
-- F. M. Hubbard

Samer

unread,
Dec 6, 2008, 12:59:44 AM12/6/08
to vim_use
Tony, thanks for your answer. I think that it makes some sense.

But still, from a syntax perspective, why did map <buffer> <S-C-m>
<Esc>:JavaImport<CR> lead to a remapping of <CR> whereas imap <buffer>
<S-C-m> <Esc>:JavaImport<CR>a didn't?

On Dec 5, 7:33 pm, Tony Mechelynck <antoine.mechely...@gmail.com>
wrote:

Tony Mechelynck

unread,
Dec 6, 2008, 10:31:52 AM12/6/08
to vim...@googlegroups.com
On 06/12/08 06:59, Samer wrote:
> Tony, thanks for your answer. I think that it makes some sense.
>
> But still, from a syntax perspective, why did map<buffer> <S-C-m>
> <Esc>:JavaImport<CR> lead to a remapping of<CR> whereas imap<buffer>
> <S-C-m> <Esc>:JavaImport<CR>a didn't?

With me it did, but ":map" (with no exclamation mark) doesn't show it
because it doesn't show any imaps. With ":map!" I saw it, when editing
the buffer in question of course, since map-<buffer> for non-current
buffers are never listed.

See ":help map-overview" and scroll down as necessary.


Best regards,
Tony.
--
FATHER: One day, lad, all this will be yours ...
PRINCE: What - the curtains?
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

Reply all
Reply to author
Forward
0 new messages