Vim: 映射ctrl+pgup和ctrl+pgdn (CTRL+Page Up/Down)键组合

7
我正在尝试将Vim命令映射到 ctrl+pgupctrl+pgdn 键组合。Vim的语法不起作用(即<PageUp><PageDown>,或<C-PageUp><C-PageDown>)。
由于默认的Vim语法无效,我猜测终端没有发送Vim所期望的ctrl+pgupctrl+pgdn字符代码。如果是这样,我不知道如何找到字面键码。我在Arch Linux上使用xfce4-terminal。
这是我尝试过的:
  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: http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_2)#Key_notation

    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: https://groups.google.com/forum/#!topic/vim_use/j85-2xQkb7s

    map [5~ :bp<cr>
    
  8. The method from this answer: https://superuser.com/questions/322983/how-to-let-ctrl-page-down-switch-tabs-inside-vim-in-terminal-app

     map \033[5;5~ :bp<cr>
    
  9. Setting different term options:

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

    My $TERM environment variable is set to xterm.

  10. Using some of the methods which this answer hints at: https://superuser.com/questions/480215/how-to-map-pagedown-and-pageup-keys-to-function-normally

     map <Esc>[5~ :bp<cr> map <kpp> :bp<cr>
  11. Trying everything above with a file under .vim/after/plugin/ instead of in .vimrc.
  12. Trying everything above with :MBEbp instead of :bp.

我还能尝试什么?

2个回答

7

好的,我已经理解了。我忽略了一个极其简单的问题,这通常是我的情况。

ctrlpgupctrlpgdn已经是xfce4-terminal本身的键盘快捷键(用于切换终端选项卡)。为了让Vim使用这些组合键,终端本身不能使用它们。所以这是xfce4-terminal的问题,而不是Vim的问题。

可以按照这里描述的方法取消xfce4-terminal的快捷键:https://unix.stackexchange.com/questions/159979/xfce4-terminal-disable-individual-shortcut

简而言之,以下是该过程:

  1. Open ~/.config/xfce4/terminal/accels.scm and uncomment/edit the lines:

    (gtk_accel_path "<Actions>/terminal-window/next-tab" "")
    (gtk_accel_path "<Actions>/terminal-window/prev-tab" "")
    

    (You can verify this change by opening a new window and clicking Tabs in the Menubar: The Previous Tab and Next Tab items should no longer display shortcuts to their right.)

  2. Put this command in .vimrc:

    map <C-PageUp> :bp<CR>
    map <C-PageDown> :bn<CR>
    

    Consider nmap instead, to restrict the shortcut to NORMAL mode.


0

你可能最接近第二点,但也许误解了说明。

Vim不知道control-pageup等键,因为这些键没有传统的termcap符号,并且它们在不同的终端上可能不同。虽然vim有一些内置的termcap信息,但不太可能有这些非传统定义。

此外,尽管ncurses通过user-definable capabilities提供了这些键的定义,但vim不使用该信息(因为它仅使用termcap接口)。

Vim可以将一系列字符映射为结果。但是,要做到这一点,您必须将字符输入到vim中。您的终端可能会发送以escape字符开头的字符序列,通常会回显为^[。在输入特殊键时,您必须防止vim吃掉该escape字符。通常的方法是先按下controlV(“字面上的下一个”字符),然后再按下特殊键。如果看到回显^[,那就是正常的。

并非所有终端都会发送有趣的(或不同的-或任何)修改键。例如,PuTTY和Konsole在这个领域的能力比xterm或rxvt差得多,通常只发送nothing。使键可见的副作用是找出您的终端是否发送了有用的内容。

进一步阅读:


当我使用这个方法来查找pgup字符的下一个字面值时,它显示为^[[5~。如果我用ctrl+pgup尝试同样的操作,就不会显示任何东西。如果我按下ctrl+pgup然后再按enter,它会显示^M,但这和只按enter所显示的字符相同。这是否意味着vim无法读取此键组合? - GreenRaccoon23

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接