2

I'm trying to adapt to vim, again, I'm doing pretty well for now but unfortunately Gvim and Vim doesn't handle the same way the alt key.

In Vim, pressing ALT+ any other key) is the same to press (ESC + any other key). Even in bash's prompt using the vi mode (set -o vi).

If I use the same shortcuts in Gvim, estranges UTF-8 characters are printed.

How can I disable

4

2 回答 2

5

在 Vim 中,按 (ALT + 任何其他键) 与按 (ESC + 任何其他键) 相同。即使在 bash 的提示符下使用 vi 模式 (set -o vi)。

Vim 不会那样做,你的终端会这样做——这就是为什么你会在该终端的其他程序中看到相同的行为,比如 bash。您需要向 gvim 添加与您期望的终端行为相匹配的行为,而不是从 gvim 中删除行为。

根据您的窗口管理器,您可能能够映射以执行您想要的操作:

# in .vimrc, or without guards in .gvimrc
if has("gui_running")
    map <m-j> (something)
endif

根据您想要的模式使用 map、nmap、imap 等。

于 2014-10-15T07:02:36.353 回答
2

正如@fred-nurk 所提到的,基于终端的vim 和gvim 之间的键映射差异取决于您的GUI 环境(窗口管理器)和终端仿真器的键映射和功能。

我还假设您的问题是指“插入模式”问题,所以我会相应地回答。

将 gvim 键映射为更接近 vim 的一种方法是重新映射每个有问题的键并禁用菜单键。老实说,这几乎就是您在 .vimrc 中某个地方(靠近底部 [?])可能需要的全部内容:

[编辑添加菜单栏切换]:

" vim.gtk/gvim: map alt+[hjkl] to normal terminal behaivior
if has("gui_running")
    " inoremap == 'ignore any other mappings'
    inoremap <M-h> <ESC>h
    inoremap <M-j> <ESC>j
    inoremap <M-k> <ESC>k
    inoremap <M-l> <ESC>l

    " uncomment to disable Alt+[menukey] menu keys (i.e. Alt+h for help)
    set winaltkeys=no " same as `:set wak=no`

    " uncomment to disable menubar
    set guioptions -=m

    " uncomment to disable icon menubar
    set guioptions -=T

    " macro to toggle window menu keys
    noremap ,wm :call ToggleWindowMenu()<CR>

    " function to toggle window menu keys
    function ToggleWindowMenu()
        if (&winaltkeys == 'yes')
            set winaltkeys=no   "turn off menu keys
            set guioptions -=m  "turn off menubar

            " uncomment to remove icon menubar
            "set guioptions -=T
        else
            set winaltkeys=yes  "turn on menu keys
            set guioptions +=m  "turn on menubar

            " uncomment to add icon menubar
            "set guioptions +=T
        endif
    endfunction
endif
于 2018-06-02T05:10:15.853 回答