Question

I've been getting used to Vim/MacVim for the last few weeks. One of main problems I seem to be having is when I scroll around using the mouse (especially when I'm trying to select large portions of text) the text insertion cursor moves too and doesn't stay where it was (like in TextMate for example). This means I've selected a large piece of text, when I scroll back up to review my selection the cursor will move which messes with the selection that I've made.

I do realise I should get used to text selection with visual mode, and I am one bit of a time, but sometimes it's the best tool to use the mouse.

Is there a way of fixing this behaviour?

Was it helpful?

Solution

:help scrolling tells you:

These commands move the contents of the window. If the cursor position is moved off of the window, the cursor is moved onto the window (with 'scrolloff' screen lines around it).

So basically I would say that it is not possible to leave the cursor where it was when you are scrolling. The cursor is always visible in your window, and therefore your visual selection will extend.

Probably you would like to xnoremap <ScrollWheelUp> <esc><ScrollWheelUp> and same for ScrollWheelDown. Use then gv to restore your selection.

OTHER TIPS

I made a screencast about Vim's changelist and jumplist which addresses the issue of Vim's cursor always being on screen. The changelist maintains a list of all of the places in your document where you have made an edit. You can move back and forward through the list with the commands g; and g, respectively. Or if you want to put your cursor back on the last place where you made an edit and go into insert mode, just press gi.

As Alois Cochard pointed out, the o key is very useful when you are in visual mode. It moves the cursor between the start and the beginning of your selection. So if your selection is larger than your screen, it will move you from one end to the other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top