Wikia

Vim Tips Wiki

Changes: Make arrow keys work in visual mode under Windows

Edit

Back to page

(Tip is dubious.)
(fix tip and incorporate comments)
 
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=864
 
|id=864
Line 6: Line 5:
 
|created=2005
 
|created=2005
 
|complexity=basic
 
|complexity=basic
|author=Bertram Scharpf
+
|author=
 
|version=6.0
 
|version=6.0
 
|rating=33/14
 
|rating=33/14
|category1=
+
|category1=Windows
 
|category2=
 
|category2=
 
}}
 
}}
On Windows, in visual mode the arrow keys do not work; they even end visual mode.
+
On Windows, new users may notice that the arrow keys end visual mode rather than extending the selection.
   
Simply put this into your vimrc:
+
If this happens, it is because of the <code>behave mswin</code> line in the default _vimrc installed on a Windows system.
<pre>
 
vnoremap <Left> h
 
vnoremap <Right> l
 
vnoremap <Up> k
 
vnoremap <Down> j
 
</pre>
 
   
and the arrow keys behave like expected.
+
The best solution is to simply remove this line from the global _vimrc, or to create your own _vimrc without it.
   
==Comments==
+
However, if you like most of the effects of <code>behave mswin</code> (see {{help|behave}}) and only want to "fix" the visual selection behavior, simply put this into your vimrc after the <code>behave mswin</code>:
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:
 
<pre>
 
source $VIMRUNTIME/mswin.vim
 
behave mswin
 
</pre>
 
 
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
 
 
<pre>
 
<pre>
 
set keymodel-=stopsel
 
set keymodel-=stopsel
 
</pre>
 
</pre>
   
or by omitting
+
==References==
<pre>
+
* {{help|:behave}}
behave mswin
+
* {{help|'keymodel'}}
</pre>
 
   
----
+
==Comments==
If you use vnoremap for it, the selection with shift+arrows will not disappear when you release shift.
 
 
Better way is using xnoremap:
 
<pre>
 
xnoremap <Left> h
 
xnoremap <Right> l
 
xnoremap <Up> k
 
xnoremap <Down> j
 
</pre>
 
 
And for ctrl+arrows movement:
 
<pre>
 
xnoremap <C-Left> B
 
xnoremap <C-Right> W
 
</pre>
 
 
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. [[User:JohnBeckett|JohnBeckett]] ([[User talk:JohnBeckett|talk]]) 07:42, July 21, 2012 (UTC)
 
 
----
 

Latest revision as of 15:46, July 23, 2012

Tip 864 Printable Monobook Previous Next

created 2005 · complexity basic · version 6.0


On Windows, new users may notice that the arrow keys end visual mode rather than extending the selection.

If this happens, it is because of the behave mswin line in the default _vimrc installed on a Windows system.

The best solution is to simply remove this line from the global _vimrc, or to create your own _vimrc without it.

However, if you like most of the effects of behave mswin (see :help behave) and only want to "fix" the visual selection behavior, simply put this into your vimrc after the behave mswin:

set keymodel-=stopsel

ReferencesEdit

CommentsEdit

Around Wikia's network

Random Wiki