Why do <C-PageUp> and <C-PageDown> not work in vim?
Asked Answered
A

3

12

I have Vim 7.2 installed on Windows. In GVim, the <C-PageUp> and <C-PageDown> work for navigation between tabs by default. However, it doesn't work for Vim.

I have even added the below lines in _vimrc, but it still does not work.

map <C-PageUp> :tabp<CR>
map <C-PageDown> :tabn<CR>

But, map and works.

map <C-left> :tabp<CR>
map <C-right> :tabn<CR>

Does anybody have a clue why?

Arcature answered 29/11, 2009 at 1:48 Comment(0)
T
12

The problem you describe is generally caused by vim's terminal settings not knowing the correct character sequence for a given key (on a console, all keystrokes are turned into a sequence of characters). It can also be caused by your console not sending a distinct character sequence for the key you're trying to press.

If it's the former problem, doing something like this can work around it:

:map <CTRL-V><CTRL-PAGEUP> :tabp<CR>

Where <CTRL-V> and <CTRL-PAGEUP> are literally those keys, not "less than, C, T, R, ... etc.".

If it's the latter problem then you need to either adjust the settings of your terminal program or get a different terminal program. (I'm not sure which of these options actually exist on Windows.)

Tenantry answered 29/11, 2009 at 2:1 Comment(2)
It turns out to be 1st problem. I literally type ":map ", then hit Ctrl-PageUp in keyborad, and then " :tabp<CR>". It works. but it shows below in _vimrc. map ¿ :tabp<CR> map Î :tabn<CR>Arcature
@g33kz0r: Link's dead. So what fixed it for you? Or delete the comment ;-)Maryrose
S
3

This may seem obvious to many, but konsole users should be aware that some versions bind ctrl-pageup / ctrl-pagedown as secondary bindings to it's own tabbed window feature, (which may not be obvious if you don't use that feature). Simply clearing them from the 'Configure Shortcuts' menu got them working in vim correctly for me. I guess other terminals may have similar features enabeld by default.

Suilmann answered 20/3, 2012 at 9:38 Comment(1)
I had this same problem and solution with gnome-terminal.Cleruchy
D
0

I'm adding this answer, taking details from vi & Vim, to integrate those that are already been given/accepted with some more details that sound very important to me.

The alredy proposed answers

It is true what the other answer says:

  • map <C-PageUp> :echo "hello"<CR> won't work because Vim doesn't know what escape sequence corresponds to the keycode <C-PageUp>;
  • one solution is to type the escape sequence explicitly: map ^[[5^ :echo "hello"<CR>, where the escape sequence ^[[5^ (which is in general different from terminal to terminal) can be obtained by Ctrl+VCtrl+PageUp.

One additional important detail

On the other hand the best solution for me is the following

set <F13>=^[[5^
map <F13> :echo "hello"<CR>

which makes use of one of additional function key codes (you can use up to <F37>). Likewise, you could have a bunch of set keycode=escapesequence all together in a single place in your .vimrc (or in another dedicated file that you source from your .vimrc, why not?).

Dever answered 21/4, 2020 at 18:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.