is it possible to disable mouse visual mode in vim? - vim

I have a problem that when I use my mouse to focus on my vim window, I often end up in Visual mode. However, I like many of the mouse functions such as resizing windows and selecting tabs.
Is there any way to leave mouse mode enabled, but disable the mouse's ability to enter Visual mode when accidentally selecting text?

Try this in your $HOME/.vimrc configuration.
set mouse=nicr
Or if you want to use on the fly in vim , try with command mode :set mouse=nicr
For some user's set mouse-=a also works, but that is not working for me.

Related

Why does Vim cursor jump to selected text when bypassing visual mode?

Vim automatic visual mode can be annoying. It's switching into visual mode when ever you left click and select a text in it. Fortunately there is the possibility to bypass this behaviour by holding shift-key while selecting text in the terminal. This bypass is useful, quickly to use at hand without having to configure vim first.
However I recently noticed that, when the terminal detects something as a link (for instance /var/www/example.com/ directory in apache vhost configs), and I try to select it using mouse+shift-key combination, it doesn't let me copy the selected text but jumps to the next similar line in the text while enabling auto visual mode again.
Why does this happen and how can I bypass that?
PS: I know about :set mouse-=a in vimrc but as I am working on different servers I don't want to have to edit vimrc each time I am on a new server.
The only text-selection vim has is visual mode. So you tell vim with mouse=a that it should use the mouse to select text. What do you expect?
You could always copy the text without your mouse at all ("+yy if you have clipboard support).
I could not reproduce your behavior with the links. Is this also happening without plugins?
But anyway, if you don't want visual mode on your mouse, you have to modify the mouse setting and stop telling vim to use visual mode on your mouse.
If there's a specific setting that you want on your main machine, but not on other servers etc then you can use an if statement in your .vimrc to specify which system you want the setting to be active on. For instance:
"My Linux machine
if readf('/etc/machine-id') == ['your-machine-id']
set mouse=a
endif
"Only on Macs
if system('uname') == "Darwin\n"
set mouse=a
endif
Someone is setting mouse=a. You can find the guilty one by executing :verbose set mouse.
Then you either have to change that or you have to create a .vimrc for your user. As far as I understand that might not be easy in your situation.
Instead of set mouse-=a you could also use set mouse= to disable all mouse stuff. This is what I prefer and it saves two keystrokes :-).
This is how I handle this problem. It might or might not be doable for you.
I have one file called .rks, that I scp to every server I have to login.
The first command after login is always
. ./.rks
This sets up my shell environment (prompt, aliases, vi editing mode etc) and creates a file
called ~/.vimrc.rks (if it doesn't exist) containing my basic Vim setup
(e.g. set mouse=). Finally it exports the variable VIMINIT:
export VIMINIT="source $HOME/.vimrc.rks"
Now Vim sources ~/.vimrc.rks on startup and I get my setup.
This way I
only have to transfer one file to all machines. Other files (like
.vimrc.rks) are created when sourcing that file.
have my personal setup without changing any default files. Others might also log in with the same user name.
I just learned, that I could automate the transfer of my setup file using ssh LocalCommand configuration. See this answer on serverfault.

Vim enters into visual mode on selecting text after El Capitan update

Issue is what the title says. Earlier I used to copy text from text files open in vim simply by selecting text and doing Ctrl + C. But now it puts me into visual mode, thus not allowing to copy the text. Its really annoying. Anybody knows any fix for this.
Thanks.
You probably have the mouse mode active. You can turn it off with:
:set mouse=
And turn it back on with
:set mouse=a
If you are using iTerm, you can leave mouse mode on all the time if you want, and hold Option when you want to select without using visual mode. I am not aware of a way to do that in OS X Terminal.
Update (from Younes in comments): For Terminal.app on El Capitan, press the Fn key to bypass the mouse mode. See this question for more.

What has changed my mouse selection behaviour?

In using vim on Linux at the terminal I expect mouse selection to behave as (e.g.):
Start insert mode
Select some other text with left mouse button
Click middle button
Selected text gets pasted in where I was inserting
I think of this as "normal terminal mouse behaviour", and expect it to work like that for all programs, not just vim. However, something changed in the past few days and vim now acts differently:
Start insert mode
Select some other text with left mouse button
My insertion point now moves to the start of the selection
My mode is changed from "Insert" to "(insert) SELECT"
Click middle button
Looks like nothing happened, but I think it has actually pasted the selection on top of itself, because if I click again the selected text appears a second time after the selection.
One other symptom: The mouse cursor is now an arrow when pointing at a vim terminal window. Other terminal windows show an I beam, and vim used to do that too.
This is a problem with vim, not terminal because
It behaves the same in Gnome terminal, Konsole, and Terminator
Other programs at terminal behave the "normal" way
I have tried changing settings for :behave, :set selectmode and :set mouse, but this has not helped (maybe I just haven't found the right combo yet?).
This problem is recent (this week), but I have not changed my vim settings relevantly in that time.
Any ideas as to what's going on here?
The command :set mouse=a suggested should enable mouse integration in all modes but this is not what you want. To stop VIM messing with the mouse settings use :set mouse= (with no letters after the equals) to prevent it from changing the mouse in any mode.

The vimrc setting and the command of coping clipboard is conflicting

Vim version is 7.2.411, operating system is CentOS 6.
By default, i can use the mouse to select the text and click right key, then copy the selection to clipboard.
Now i want to use this option set mouse=a that i set it in ~/.vimrc file,
but the previous operation is not working. Whatever i try "+y or "*y, still not works.
I just want to use the function that copys the yand text to clipboard, simultaneously, and the set mouse=a to be set in .vimrc file.
Check whether you have set clipboard=autoselect,autoselectml and set guioptions+=a set (you'll probably have some other "letters" in there as well)? The a is related to copying to the cliboard. The mouse=a only enables you to use the mouse in all modes.
From your description it sounds like you're using Vim in a terminal. By default, the terminal is handling the mouse clicks, so it's the terminal selecting and copying the text. When you set mouse=a, Vim handles the mouse itself, so selecting doesn't copy to the clipboard.
If the version of Vim you're using was compiled without X11 support, you can't copy and paste from inside Vim. This would explain why "+y and "*y don't work. You should try to install a "full" Vim version using your distribution's package manager. Be sure to run vim and not vi from the command-line, to get the proper version.
In this case, you can still let the terminal handle mouse-clicks (instead of Vim) by holding shift when you click or drag. This way, you'll get the behaviour you had previously had before you set mouse=a.

Selection automatically put into X11 clipboard - VIM

In my previous Linux install, when I selected some text in visual mode (without the mouse!), it would automatically put it in my X11 clipboard. Then I could naturally paste this text anywhere else using the mouse middle button.
With my new Linux installation, this doesn't work anymore (merely selecting text in visual mode doesn't put it in X11 clipboard anymore).
How can I get this nice feature back?
(I am not interested into the "*y or "+y solutions, which by the way don't work on my system.)
Thanks in advance!
The visual selection (v, V, or CTRL-V) can automatically be copied to the
X11 selection (* buffer).
In non-gui mode the clipboard option controls this (only supported if
+xterm_clipboard appears when you type vim --version). In gui mode
guioptions controls it.
This makes all Visual mode selections automatically go to the X11 primary
selection:
set clipboard+=autoselect
set guioptions+=a
This turns it off:
set clipboard-=autoselect
set guioptions-=a
In vim see:
help 'clipboard'
(single quotes required)
Use:
set guioptions+=a
This works with the GUI (Gvim). Reference is at :help guioptions_a.
*guioptions_a* *'go-a'*
'a' Autoselect: If present, then whenever VISUAL mode is started,
or the Visual area extended, Vim tries to become the owner of
the windowing system's global selection. This means that the
Visually highlighted text is available for pasting into other
applications as well as into Vim itself. When the Visual mode
ends, possibly due to an operation on the text, or when an
application wants to paste the selection, the highlighted text
is automatically yanked into the "* selection register.
Thus the selection is still available for pasting into other
applications after the VISUAL mode has ended.
If not present, then Vim won't become the owner of the
windowing system's global selection unless explicitly told to
by a yank or delete operation for the "* register.
The same applies to the modeless selection.
When using Vim inside gnome-terminal on Arch and Gentoo Linux this functionality just works.
When using Vim inside Konsole this does not work.
Using gvim -v will launch a terminal version of GVim where set guioptions+=a works:
any text selected within that Vim is automatically copied to Linux's selection buffer.
To paste text from the selection buffer press the middle mouse button
On my Debian I got it working after installing vim-gnome package.
A comment from pkg-vim-maintainers mailing list instructs to install either vim-gtk, vim-gnome or vim-lesstif.
With my new installation of Kali, I solved the issue above by installing vim-gtk package for gnome-terminal. The vim-gtk package changes the "-xterm_clipboard" to "+xterm_clipboard", and the problem is solved. After selecting text in vim, the text will be copied to system clipboard automatically.

Resources