Using middle mouse click to paste text enters insert mode

This is fully answered here. See the excellent linked answer for details and alternative solution.

Short answer: put :set t_BE= in your .vimrc file.


Try disabling vim's mouse mode with :set mouse=. Add that to your ~/.vimrc (without the :). You may also need to comment out any existing set mouse= line if there is one.

This will disable all of vim's mouse-handling, returning to the default X handling of the mouse - i.e. left-click to begin selection, right-click to extend selection, and middle-click to paste. In particular, note that clicking the mouse in the vim window will not move the mouse cursor, or interact with vim's Visual selection mode.


BTW, rather than use on the mouse for sub-standard versions of features built-in to vim, have you considered using :map, or recording macros?

It's easy enough to map sequences of commands to keys, e.g. :map , JJJj to map them to the comma key.

Or use q followed by a letter or digit to record a macro into a register. e.g. qaJJJjq to bind JJJj to @a. You can then run that macro just by typing @a. You can also record numerous macros and map them to , or whatever as needed, to quickly switch between multiple common operations. e.g. :map , @a

I use the , (comma) key for short-term (i.e. current editing session) mappings because it's not mapped to anything I ever use. For permanent mappings, I use function keys and set them in my ~/.vimrc file. e.g. map <F5> {!}par^V^M} maps the F5 key to move the cursor to the start of the current paragraph, pipe it through the par paragraph reformatter, and then move the cursor past the paragraph (vim has built-in paragraph reformatting but I prefer par).

Note that mappings and macros can be as arbitrarily complex as you want. Recording a macro with q will record whatever you type until you type q again. and if you want to embed a control character such as ESC or carriage-return into a :map command, you can use Ctrl-V aka ^V to "escape" them while entering the map - e.g.

:map , Do^V^[!!date -R^V^MkJ

That maps , to replace the remainder of the current line (from the current cursor position) with the RFC-2822 formatted current date & time.

or if you wanted to search for a pattern, join three lines, then search again, you could do something like this:

:map , JJJn

Then perform the first search with /pattern<enter>, and press , to do the join and search for the next occurrence. At that point you can choose whether to join and search again (press , again) or just search again (press n) or do something else entirely. I routinely do things like this when I don't want to do a simple search-and-replace but want to decide each time (e.g. when there's likely to be too many false-positive matches and it's going to take longer than it's worth to craft a perfect regexp search pattern)

The above is only a very simple example of what this can be used for - it's not much different to just typing 3J and then alternating between pressing n for find-next and . to repeat last command...and you can, of course, :map , .n. It really becomes useful when you need to repeat a sequence of commands that can't be repeated with just .

Tags:

Vim