Why does < C> (CTRL+A) not work under gvim on windows?

后端 未结 5 2104
情歌与酒
情歌与酒 2020-12-24 13:30

I\'m trying to use the < C-a> (CTRL+A) shorcut under vim to increment a variable under the cursor. This works fine under vim running on Linux. Howev

相关标签:
5条回答
  • 2020-12-24 13:49

    Vim on Windows has specialized key mappings by default to make shortcuts more "windows-y". These are specified in the $VIMRUNTIME\mswin.vim file, which is loaded via your vimrc unless you disabled it. You can edit the mswin.vim file (you may want to edit a copy instead, changing your vimrc to use your edited copy instead).

    I'm not entirely sure it's a default Vim mapping, since the only reference I can find on Ctrl+A in the help file is this, which doesn't seem to do what you are referring to:

    *c_CTRL-A*
    CTRL-A      All names that match the pattern in front of the cursor are
                  inserted.
    

    so you may want to check your Linux box to see if any plugins or anything change the key mapping. (Of course, it may be that I just can't find the appropriate part of the Vim help.)

    0 讨论(0)
  • 2020-12-24 13:51

    I know I'm late to the party, but I thought I'd share the following:

    nnoremap <kPlus> <C-a>
    nnoremap <kMinus> <C-x>
    

    This remaps increment to the + key on the numeric keypad and decrement to the - key. It's the solution I've used in my own _vimrc file on Windows. It keeps the Windows compatibility and is easier to remember than the original Ctrl+A/Ctrl+X as well.

    0 讨论(0)
  • 2020-12-24 13:53

    in the current version of mswin.vim provided with gvim, the file checks for the value of a global named skip_loading_mswin; If set, the rest of the file is skipped; thus it is sufficient to add

    let skip_loading_mswin=1
    

    to $HOME/_vimrc and normal vim bindings will be restored the next time you start vim.

    0 讨论(0)
  • 2020-12-24 13:54

    This is because of mswin.vim that is sourced by the default _vimrc generated when you install vim. Just override your _vimrc with the .vimrc you are using under *nix, or delete mswin.vim.

    0 讨论(0)
  • 2020-12-24 14:01

    If you just do not like CtrlA behaviour but are fine with other windows behaviours in VIM (like CtrlZ for undo), just disable that specific line:

    1. Edit said file (c:\Program Files\Vim\vim73\mswin.vim for me)
    2. Find the paragraph starting with CTRL-A is Select all
    3. Prepend all (6) lines of that paragraph with opening brackets (")
    4. Reopen your GVIM windows.

    You can still "select all" by typing ggVG (position cursor at first line, select entire line, select until the last line of the document).

    Happy incrementing!

    0 讨论(0)
提交回复
热议问题