Friday, May 27, 2011

Re: Incorrect interpretation of keycodes.

On 27/05/11 17:00, Daniel Fishman wrote:
> On Fri, 27 May 2011 15:32:06 +0200, Tony Mechelynck<antoine.mechelynck@gmail.com> wrote:
>
>>
>> 1. For non-printable keys outside the ASCII or Unicode "universe", how
>> they are represented is at the mercy of the keyboard driver and terminal.
>>
>> 2. For historical reasons, on many terminals, the backspace key does not
>> send a backspace code, nor does the delete key send a delete code. See,
>> among others, :help :fixdel
>
> And indeed this is the case on my machine. But I know that on my terminal
> 'Backspace' sends ascii code 127 (I know it because 'showkey' tells me that),
> which is<Del> special key. Why then vim mistakenly recognizes it as<BS> key,
> which is ascii code 8?

Probably because Vim somehow knows (maybe from the termcap or terminfo
database for your terminal) that your Backspace key sends 127. Now when
you hit the Backspace key, Vim interprets it as the Backspace key, and
you're telling me this is wrong? You ought to be happy.

>
>> 3. Ctrl-K (in Insert mode) is overloaded: when followed by _two_ ASCII
>> or Unicode keys, which may be control characters but the latter facility
>> is rarely used, it ushers in a digraph (q.v.); when followed by one
>> non-Unicode "special key", it inseers that key's<> notation. Ctrl-K
>> Ctrl-H is still waiting for the second half of the digraph (we're in the
>> former case); only then will it look up in its table to see that there
>> is no defined digraph for that key pair. You could see this by looking
>> at the bottom right of the screen with 'showcmd' true
>
> This is incorrect. Quoting from the documentation:
>
> ----------------------------------------------------
> If a digraph with {char1}{char2} does not exist, Vim searches for a digraph
> {char2}{char1}. This helps when you don't remember which character comes
> first.
>
> Note that when you enter CTRL-K {char1}, where {char1} is a special key, Vim
> enters the code for that special key. This is not a digraph.
> ----------------------------------------------------

OK then; ...that there is no defined digraph for that key pair, and also
not for the same two characters in the opposite order. Do I have to
always spell everything out all the way if I don't want to be accused of
"not being correct"? With 'showcmd' true, you could still have seen ^K^H
waiting for some additional character at the bottom right corner of your
screen.

>
> It means that when vim recognizes {char1} as a special key, it knows that
> it is not a digraph and does not wait for {char2} (at least this is what
> supposed to happen). It means that if after<ctrl-k> <ctrl-h> vim still
> waits for {char2}, then<ctrl-h> was not recognized as a special key, which
> is the problem I am talking about.

Ctrl-H is indeed not a "special" key (like Home, End, F1, F2, etc.,
which have no representation in ASCII or even in Unicode), it is an
ASCII control key. Without the Ctrl modifier it is even a printing key.

>
>> 5. All this means that the sentence "insert the key name by pressing
>> CTRL-K and then the key you want the name for" is misleading for
>> printing or control keys, including some of those listed under ":help
>> keycodes".
>
> According to what I have written above, the sentence is correct for control
> keys. I agree that it is misleading for printable charaters.
>
> P.S.: I checked and found that there is no digraph '<2' or '2<'.
> Therefore, '<ctrl-k><2' should print '<lt>2', since after you type 2 vim
> should understand that neither '<2' not '2<' is a digraph, and print name
> of special character and the additional redundant char '2'.
> Instead, it just prints 2.
>

The less-than key is not a special key, it is a printing key. What is
strange here is that after Ctrl-K < I can type any number of digits in
gvim, the sequence is not terminated; it only terminates (with a beep)
once I hit a nondigit. _That_ could be a bug.


Best regards,
Tony.
--
Q: What's a light-year?
A: One-third less calories than a regular year.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment