Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 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 at 10:53

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:

augroup NO_CURSOR_MOVE_ON_SELECTION
  au!
  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

:set

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

:mouse=nvc

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

 
discard

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.