Use of CTRL-K to enter a CR character

4 views
Skip to first unread message

fritzophrenic

unread,
Dec 4, 2008, 9:19:26 AM12/4/08
to vim_use
This tip:

http://vim.wikia.com/wiki/Change_end-of-line_format_for_dos-mac-unix

mentions the ability to enter a CR character (^M) on the command line
by typing <C-K><Enter><Enter>.

It works, but I'm a little confused as to why. I would expect <C-K>CR
to insert a ^M, because that is the defined digraph. This works as
expected. I would expect <C-K><Enter> to insert <CR> (the 4 literal
characters) as defined for "special keys" in :help c_CTRL-K. This does
nothing, though <C-K><S-Enter> does insert a literal "<S-CR>". I
certainly don't understand why <C-K><Enter><Enter> inserts the ^M
character.

What's going on?

Tony Mechelynck

unread,
Dec 4, 2008, 5:03:32 PM12/4/08
to vim...@googlegroups.com

OK, here's (after some experimenting) what I think is happening. All the
following assume Insert mode

Special case 1: <Ctrl-K> <Space> <key1> or <Ctrl-K> <key1> <Space>
where <key1> corresponds to a single character in the range [0x00-0x7F]:
enter that character plus 0x80. This is normally the same as Alt-<key1>.

Special case 2: <Ctrl-K> <key1>
where <key1> does _not_ represent a character: enter the <>
representation of of <key1>. This is not a digraph.

General case: <Ctrl-K> <key1> <key2>
If there is a defined digraph for <key1> <key2>, enter it into the
buffer. Otherwise, if there is a defined digraph for <key2> <key1>,
enter that. Otherwise, enter <key2> (and discard <key1>).

When you hit <Ctrl-K> <Enter> <Enter> you are not in Special case 2,
because <Enter> does represent a character, namely the carriage-return
or Ctrl-M character 0x0D. So you fall back onto the third branch of the
general case, and you get a ^M (a literal carriage-return), exactly as
if you had hit Ctrl-V followed by Enter.

When you hit <Ctrl-K> <Shift-Enter>, gvim knows that Shift-Enter is not
the same as Enter, so it does not regard it as the Ctrl-M character but
as "not a character" and you get Special case 2. (Console Vim does not
always notice the difference between Enter and Shift-Enter -- on my
Linux system it doesn't, neither in KDE konsole not in the Linux
raw-text console.)


Best regards,
Tony.
--
You will think of something funnier than this to add to the fortunes.

John Beckett

unread,
Dec 4, 2008, 5:43:32 PM12/4/08
to vim...@googlegroups.com
fritzophrenic wrote:
> http://vim.wikia.com/wiki/Change_end-of-line_format_for_dos-mac-unix
>
> mentions the ability to enter a CR character (^M) on the
> command line by typing <C-K><Enter><Enter>.

Thanks for fixing it (by moving the new stuff to a more appropriate place). I had
that on my to-do list. I also was/am perplexed.

John

Reply all
Reply to author
Forward
0 new messages