On Sat, 21 Jan 2012, Chris Jones wrote:

On Fri, Jan 20, 2012 at 06:31:45PM EST, Gary Johnson wrote:

Someone just posted a question to superuser [...] in which they mentioned discovering that Shift-Enter is the same as Ctrl-F.

So why bother?

Because it's undocumented.


For an explanation: It seems to me that it's an accident of implementation. The Vim-internal key names I see mapped to nv_down (the function that implements moving downward some number of lines) in src/normal.c are:

NL, Ctrl_M, Ctrl_N, '+', 'j', and K_DOWN

In nv_down, the first thing it checks is whether MOD_MASK_SHIFT is set. In the comment, it indicates that it's checking for <S-Down>, which gets translated to "page down" (nv_page) rather than "line down".

My guess is that GUI versions of Vim, where Enter != Shift-Enter, it also catches Shift + NL.

It doesn't catch 'J' because that's a different function (nv_join). I'm not sure why it doesn't catch Ctrl_M, Ctrl_N, or '+'. Again, hypothesizing, probably because Ctrl+letter is already weird in Vim, so there's possibly special handling for it somewhere else (which doesn't pass Ctrl+Shift+letter to the function).

'Shift-+' is hard to type on QWERTY (where '+' already requires 'Shift'). But xmodmap'ing it to something without Shift, it still doesn't get caught.


I experimented a little and discovered that that's true, but only in gvim, not vim, and it's not documented anywhere that I could find, searching for "shift.enter", "s.enter", or "s.cr".

It's not a mapping, as ":map <S-CR>" doesn't show anything and it works when gvim is started as "gvim -N -u NONE".

My keyboard, using either GNOME Terminal or xterm with vim, doesn't seem to generate anything special for Shift-Enter, just ^M. I guess that's why it doesn't work with vim.

I experimented on a Linux system, but I see that it behaves the same in gvim on Windows.

Is there some reason that this isn't documented, or am I just not able to find it?

Interestingly, (@ChrisJones at least)..

| $ xmodmap -e "keysym Return = Return Next"

... enables Shift-Enter in Vim ‘^gvim’.

Go figure...

For anyone not familiar with xmodmap, Return is the X11 Keysym usually mapped to the 'Enter' key, and Next is the X11 Keysym for the 'PageDown', 'PageDn', or 'PgDn' key. So, what Chris posted maps (on a QWERTY-like keyboard) the key combinations <Enter> and <Shift>+<Enter> to (in Vim notation:) <CR> and <PageDown>. Thus, in every program, Shift+Enter would be seen as PageDown.

--
Best,
Ben

--
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

Reply via email to