GreenRaccoon23 GreenRaccoon23 - 3 months ago 28x
Linux Question

Vim: Map ctrl+pgup and ctrl+pgdn (CTRL+Page Up/Down) key combinations

I'm trying to map Vim commands to the

key combinations. The vim syntax for these keys does not work (i.e.,
, or

Since the default vim syntax doesn't work, I'm guessing that the Terminal isn't sending the character codes for
which Vim is expecting. If that's true, I'm not sure how to find out what the literal key codes are. I'm using xfce4-terminal on Arch Linux.

Here's what I've tried:

  1. The usual method:

    map <C-PageUp> :bp<cr>

  2. Setting it from the command line with this answer's method: Why <C-PageUp> and <C-PageDown> not work in vim?

    :map <CTRL-V><CTRL-PAGEUP> :bp<cr>

    When I type the command above in the command line, nothing shows:

    map :bp<cr>

    And Vim says
    No mapping found

  3. This method from the Vim wiki:

    set <PageUp>=<type Ctrl-V><type PageUp> "^[[5~
    map <C-PageUp> :bp<cr>

  4. A modification of that answer:

    set <C-PageUp>=<type Ctrl-V><type Ctrl+PageUp> "^M
    map <C-PageUp> :bp<cr>

  5. After realizing that
    <type *>
    was a user command, I did these commands, and vim pasted output. I replaced
    <type *>
    with this output:

    set <PageUp>=^[[5~
    map <C-PageUp> :bp<cr>
    " Also:
    set <PageUp>=[[5~
    map <C-PageUp> :bp<cr>
    " Also:
    set <PageUp>=<^[[5~>
    map <C-PageUp> :bp<cr>
    " Also:
    set <PageUp>=<[[5~>
    map <C-PageUp> :bp<cr>
    " Also:
    set <C-PageUp>=^M
    map <C-PageUp> :bp<cr>
    " Also:
    set <C-PageUp>=<^M>
    map <C-PageUp> :bp<cr>

  6. Trying all of the methods in 5, but without setting an option first. E.g.:

    map <C-[[5~> :bp<cr>

  7. The method from this answer:!topic/vim_use/j85-2xQkb7s

    map [5~ :bp<cr>

  8. The method from this answer:

    map \033[5;5~ :bp<cr>

  9. Setting different term options:

    set term=xterm
    " Also:
    set term=xterm-256color

    environment variable is set to

  10. Using some of the methods which this answer hints at:

    map <Esc>[5~ :bp<cr>
    map <kpp> :bp<cr>

  11. Trying everything above with a file under
    instead of in

  12. Trying everything above with
    instead of

What else can I try?


Alright, I figured it out. I was overlooking something extremely simple, which is usually the case for me.

ctrlpgup and ctrlpgdn were already keyboard shortcuts in xfce4-terminal itself (for switching Terminal tabs). In order to allow Vim to use these key combinations, they cannot be used by the Terminal itself. So this was an issue with xfce4-terminal, not Vim.

xfce4-terminal shortcuts can be unset with the method described here:

In short, here's the process:

  1. Open Settings (xfce4-settings-manager), go to Appearance > Settings, and toggle on Enable editable accelerators.
  2. Edit/Create ~/.gtkrc-2.0 and append this line to the file:

  3. Open an xfce4-terminal window, and then open another tab in the same window.
  4. Highlight over Tabs > Previous Tab, press Backspace, and type in a new keyboard combination.
  5. Repeat step 4 with Tabs > Next Tab.
  6. Put this command in .vimrc:

    map <C-PageUp> :bp<cr>