I am (having to) using gvim in windows. I was used to the linux environment where when I select text using mouse the cursor position wont change. Now , with gvim in windows,

My problem is something like this -

  1. while I am editing in line 6
  2. and when I am having to copy "hellovim" from line 3
  3. and when I click with mouse on "hellovim" to copy it
  4. then the cursor gets moved to "hellovim" on line 3
  5. where as I would like the cursor to stay on line 6

How can I do this


2 Answers 2


There is no option in the gvim doc that allows to do exactly what you want when editing your vimrc file. FYI, options are available here: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#CursorMoved

However, you can add the following code to your vimrc file:

  au MenuPopup * let g:oldmouse=&mouse | set mouse=
  au CursorMoved * if exists('g:oldmouse') | let &mouse=g:oldmouse | unlet g:oldmouse | endif
augroup EN

What it does: It records the cursor position on RightClick event (the one that displays the contextual menu). Then if you do a selection, the cursor will remain to the recorded position (and will not change). Once done, the recorded posisition is deleted on cursor movement, e.g. hitting a row, so that you can still move the cursor by click.

Of course you can use another event than the right click.

PS: it is like you create a "selection" state, activated by right clicking (or anything else you prefer) and deactivated by cursor move with keyboard. During this state, all your selections won't change the cursor position.


Take a look at your mouse option settings.

gvim afile

To show your current options do


Look for the mouse=<some value> it's probably mouse=a this means the mouse works in all modes. You can select which modes the mouse will operate. So


Will set the mouse only to work in, Normal, Visual and Command mode (insert mode omitted)

Modes can be:

n = Normal mode
v = Visual mode
c = Command mode
i = Insert mode
a = all modes

Now when you are inserting text you can still select with mouse and cursor will remain at your current insert position.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .