Make arrow keys work in visual mode under Windows
Talk0this wiki
created 2005 · complexity basic · author Bertram Scharpf · version 6.0
On Windows, in visual mode the arrow keys do not work; they even end visual mode.
Simply put this into your vimrc:
vnoremap <Left> h vnoremap <Right> l vnoremap <Up> k vnoremap <Down> j
and the arrow keys behave like expected.
Comments
You can also add "behave xterm" to your vimrc, this will make the visual mode behave as expected. Or hold down the Shift key while selecting with the arrows. I guess this was added to make Vim behave more like a normal Windows text editor. Very confusing for experienced Vim users.
Also take a look at you system _vimrc file. There might be following lines:
source $VIMRUNTIME/mswin.vim behave mswin
I deleted both of them an inserted some useful options that were set in vimrc_example.vim. After that Vim works under Windows like under Linux.
The same could be done by saying
set keymodel-=stopsel
or by omitting
behave mswin
If you use vnoremap for it, the selection with shift+arrows will not disappear when you release shift.
Better way is using xnoremap:
xnoremap <Left> h xnoremap <Right> l xnoremap <Up> k xnoremap <Down> j
And for ctrl+arrows movement:
xnoremap <C-Left> B xnoremap <C-Right> W
and the arrow keys behave like expected.
- This tip, and the comments, are dubious (totally wrong?). I guess the original tip is something to do with a setup that uses the broken-by-design "behave mswin", and the various "fixes" are trying to work around that? For the text to mean anything, it would have to specify the environment for which it is intended, what the problem is, and what the solution does. It would be helpful to also say how it improves default Vim behaviour. JohnBeckett (talk) 07:42, July 21, 2012 (UTC)