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)?
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.
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.)
Adding and subtracting
*CTRL-A*
CTRL-A Add [count] to the number or alphabetic character at or after the cursor. {not in Vi}
*CTRL-X*
CTRL-X Subtract [count] from the number or alphabetic character at or after the cursor. {not in Vi}
The CTRL-A and CTRL-X commands work for (signed) decimal numbers, unsigned octal and hexadecimal numbers and alphabetic characters. This depends on the 'nrformats' option. - When 'nrformats' includes "octal", Vim considers numbers starting with a '0' to be octal, unless the number includes a '8' or '9'. Other numbers are decimal and may have a preceding minus sign. If the cursor is on a number, the commands apply to that number; otherwise Vim uses the number to the right of the cursor. - When 'nrformats' includes "hex", Vim assumes numbers starting with '0x' or '0X' are hexadecimal. The case of the rightmost letter in the number determines the case of the resulting hexadecimal number. If there is no letter in the current number, Vim uses the previously detected case. - When 'nrformats' includes "alpha", Vim will change the alphabetic character under or after the cursor. This is useful to make lists with an alphabetic index.
For numbers with leading zeros (including all octal and hexadecimal numbers), Vim preserves the number of characters in the number when possible. CTRL-A on "0077" results in "0100", CTRL-X on "0x100" results in "0x0ff". There is one exception: When a number that starts with a zero is found not to be octal (it contains a '8' or '9'), but 'nrformats' does include "octal", leading zeros are removed to avoid that the result may be recognized as an octal number.
Note that when 'nrformats' includes "octal", decimal numbers with leading zeros cause mistakes, because they can be confused with octal numbers.
The CTRL-A command is very useful in a macro. Example: Use the following steps to make a numbered list.
- Create the first list entry, make sure it starts with a number.
- qa - start recording into register 'a'
- Y - yank the entry
- p - put a copy of the entry below the first one
- CTRL-A - increment the number
- q - stop recording
- <count>@a - repeat the yank, put and increment <count> times