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. However when I try to do this in gvim under windows it "selects all" (i.e. highlights or visually selects all text in the current window). How can I change this behaviour or alternatively how can I recover the increment variable functionality (e.g. perhaps with a different key mapping)?
-
see this http://stackoverflow.com/questions/66919/how-to-increment-in-vim-under-windows-where-ctrl-a-does-not-work.I think Paul's answer will be fine – lee kim May 09 '13 at 08:10
5 Answers
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.

- 31,979
- 7
- 69
- 83
-
11
-
1This can be worked around with mrswin.vim: http://www.vim.org/scripts/script.php?script_id=514 – Ed Brannin Feb 17 '10 at 13:57
-
3
-
2
-
1
-
1"mswin.vim" is evil, because no one comes from linux- to windows-[g]vim, think about something like that! – tron5 Aug 06 '15 at 10:13
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.

- 5,106
- 4
- 34
- 52

- 19,940
- 10
- 72
- 93
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.)

- 54,231
- 8
- 72
- 83
-
':h CTRL-A' works fine -> http://vimdoc.sourceforge.net/htmldoc/change.html#CTRL-A – Luc Hermitte Nov 14 '08 at 12:45
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.

- 151,563
- 33
- 264
- 304
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:
- Edit said file (
c:\Program Files\Vim\vim73\mswin.vim
for me) - Find the paragraph starting with
CTRL-A is Select all
- Prepend all (6) lines of that paragraph with opening brackets (
"
) - 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!

- 7,475
- 12
- 47
- 83

- 675
- 1
- 11
- 26