Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
Are the gvim versions the same? Same configurations? – vonbrand Mar 6 '14 at 13:45
Duplicate of stackoverflow.com/questions/22226025/…; please don't post the same question to multiple sites in parallel! – Ingo Karkat Mar 7 '14 at 10:53

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.

Hope it helps.

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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.