【问题标题】:How to make ALT works in gvim as in vim?如何使 ALT 在 gvim 中像在 vim 中一样工作?
【发布时间】:2014-12-09 13:21:28
【问题描述】:

我再次尝试适应 vim,我现在做得很好,但不幸的是 Gvim 和 Vim 处理 alt 键的方式不同。

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

如果我在 Gvim 中使用相同的快捷方式,则会打印出 UTF-8 字符。

如何禁用

【问题讨论】:

    标签: bash vim shortcut alt-key


    【解决方案1】:

    在 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...。

    【讨论】:

    • 我怎样才能将 ALT 映射到像 ESC 一样的行为?我已经尝试为它绘制地图,但没有成功。即使我处于正常或插入模式,我也需要将 ALT 键映射到非正常模式。我该怎么做?
    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-16
      • 2015-04-15
      • 2016-05-21
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多