How to increment in vim under windows (where CTRL-A does not work…)

后端 未结 7 2194
不知归路
不知归路 2020-12-08 15:32

While CtrlX works fine in vim under windows, CtrlA selects all (duh).

Is there a way to increment a number with a keystro

相关标签:
7条回答
  • 2020-12-08 15:39

    It seems that the CtrlA got mapped somewhere in startup. As suggested before, use:

    unmap <c-x>

    I would use unmap, not nunmap.

    0 讨论(0)
  • 2020-12-08 15:46

    You can make CtrlA to increment in windows by opening up the 'mswin.vim' file in your vim directory and finding the section that looks like:

    " CTRL-A is Select all
    noremap <C-A> gggH<C-O>G
    inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
    cnoremap <C-A> <C-C>gggH<C-O>G
    onoremap <C-A> <C-C>gggH<C-O>G
    snoremap <C-A> <C-C>gggH<C-O>G
    xnoremap <C-A> <C-C>ggVG
    

    Comment out all of these lines as follows:

    " CTRL-A is Select all
    "noremap <C-A> gggH<C-O>G
    "inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
    "cnoremap <C-A> <C-C>gggH<C-O>G
    "onoremap <C-A> <C-C>gggH<C-O>G
    "snoremap <C-A> <C-C>gggH<C-O>G
    "xnoremap <C-A> <C-C>ggVG
    

    and the CtrlA keystroke will increment.

    This is a pretty nice option when your keyboard doesn't have a real number pad.

    0 讨论(0)
  • 2020-12-08 15:46

    A similar problem occurs under GNU/Linux when using Vim with mswin.vim. Remapping Alt+X to Ctrl+A prior to evoking mswin.vim solved my issue.

    execute "set <A-x>=\ex"
    noremap <A-x> <C-A>
    source $VIMRUNTIME/mswin.vim
    behave mswin
    

    Now, Alt+X and Ctrl+X respectively increase and decrease numbers in Vim.

    Mapping to Alt key combinations is often not evident in Vim; read more about this here.

    0 讨论(0)
  • 2020-12-08 15:47

    I realize that this is an old question, but I ran across another option today based on the following question. Making gvim act like it does on linux will allow CTRL-A to work as you expect it to:

    how to make gvim on windows behave exacly like linux console vim?

    There is a section of the _vimrc that has the following items. These cause many of the control characters to act like they do on Windows.

    set nocompatible
    source $VIMRUNTIME/vimrc_example.vim
    source $VIMRUNTIME/mswin.vim
    behave mswin
    

    I commented out (with ") the mswin lines and the set nocompatible line. From there, I added set compatible. This causes gvim to act like it does on linux. Thus, mine looks something like:

    set compatible
    source $VIMRUNTIME/vimrc_example.vim
    "set nocompatible
    "source $VIMRUNTIME/mswin.vim
    "behave mswin
    

    I just learned this trick today, so if I'm not completely correct in my information, please let me know.

    0 讨论(0)
  • 2020-12-08 15:48

    Try Ctrl-NumPad + ?

    (from here)

    0 讨论(0)
  • 2020-12-08 15:50

    I am using cygwin terminal + screen, so <c-a> is captured by the terminal multiplexer. I used this mapping:

    :noremap <c-i> <c-a>

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