11

i'm not very experienced in VIM. i'm using VIM with putty, and i often use mouse scroll and move text cursor with mouse. also sometimes i need to paste some code from windows clipboard, so i have to type ":set mouse=" to turn off mouse handling in VIM, paste the code with right mouse button and then turn mouse handling on again with ":set mouse=a". i'm looking for a better way to do it.

1

4 Answers 4

20

Simply by <Shift> + LeftMouse to do a selection, <Shift> + RightMouse to paste your code as usual (set mouse="" state)

3
  • I have no idea why I didn't think to suggest this! +1
    – Cascabel
    Commented Oct 15, 2009 at 18:29
  • I have been looking for this answer for months. Thanks!
    – cori
    Commented Feb 13, 2011 at 3:44
  • To paste, use shift + insert if the shift + right-mouse doesn't work. Also, shift + left-mouse doesn't work for large visual blocks where you have to scroll. If anyone figures that out....share how....and you win.
    – dhaupin
    Commented Oct 21, 2016 at 20:10
2

Here's an excerpt from my vimrc. It maps a key to toggle the mouse mode between vim and external handling ("a" and ""). It's mapped twice so that it works both in normal and input mode, and it echoes which mode you've ended up in (though that'll be obscured in insert mode if you have showmode turned on).

" toggle between terminal and vim mouse
map <silent><F12> :let &mouse=(&mouse == "a"?"":"a")<CR>:call ShowMouseMode()<CR>
imap <silent><F12> :let &mouse=(&mouse == "a"?"":"a")<CR>:call ShowMouseMode()<CR>
function ShowMouseMode()
    if (&mouse == 'a')
        echo "mouse-vim"
    else
        echo "mouse-xterm"
    endif
endfunction
0

Most VIM purists would tell you: "Stop using the mouse for movement then".

Hopefully someone who uses the mouse in VIM can help you with making the mouse stuff work better, but if you're interested, I suggest the following helpful key combos to make moving your cursor/view easier in VIM:

h,j,k,l: left, down, up, right.
H: Move cursor to the top of the visible screen.
L: Move cursor to the bottom of the visible screen.
G: Move cursor to the bottom of the file.
gg: Move cursor to the top of the file.
$: Move cursor to the end of the current line.
0: Move cursor to the very beginning of the current line.
^: Move cursor to the first non-whitespace character of the current line.
Ctrl + f: Move forward/down one page.
Ctrl + b: Move back/up one page.

Hopefully those help free you from the mouse, if you're interested, if not, hopefully someone has some mouse suggestions.

1
  • I'd consider myself a Vim purist - and more to the point, a general mouse-avoider - but I think you'll find that for making large visual mode selections with interesting endpoints, the mouse is probably faster, even if you know that you can manage it with something like vL3kf'2w.
    – Cascabel
    Commented Oct 14, 2009 at 19:39
-2

This tutorial here is quite good http://www.vi-improved.org/tutorial.php

It's a log of someone teaching someone over chat so it goes through things slowly.

1
  • This is a vim tutorial. It doesn't contain anything regarding the question.
    – innaM
    Commented Oct 14, 2009 at 20:29

You must log in to answer this question.