Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)?

like image 886
snth Avatar asked Nov 14 '08 10:11

snth


3 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.

like image 90
Luc Hermitte Avatar answered Sep 20 '22 21:09

Luc Hermitte


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.

like image 20
Matthew Strawbridge Avatar answered Sep 19 '22 21:09

Matthew Strawbridge


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.)

like image 40
Michael Madsen Avatar answered Sep 22 '22 21:09

Michael Madsen