Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Disable vim automatic visual mode on mouse select
Disable vim automatic visual mode on mouse select
issue: :set mouse-=a
add to ~/.vimrc: set mouse-=a
my ~/.vimrc for preserving global defaults and only changing one option:
source $VIMRUNTIME/defaults.vim
set mouse-=a
@fhaist

This comment has been minimized.

Copy link

@fhaist fhaist commented Mar 22, 2018

Thank you. This issue was driving me nuts.

@efidoman

This comment has been minimized.

Copy link

@efidoman efidoman commented Mar 31, 2018

Yes, thanks so much. ssh vi copy/paste was almost impossible for me without this change.

@dbdq

This comment has been minimized.

Copy link

@dbdq dbdq commented Apr 3, 2018

Thanks for solving this issue. This "feature" was extremely counter-productive.

@thomskys

This comment has been minimized.

Copy link

@thomskys thomskys commented Apr 5, 2018

Thanks a lot, very annoying feature.

@unixadmin-comcast

This comment has been minimized.

Copy link

@unixadmin-comcast unixadmin-comcast commented Apr 22, 2018

I thought the 'compatible' option was on by default, obviously it may have changed in some releases. So if you prefer more of a static/generic old-school Vi experience from Vim in general consider that you can also manually set the 'compatible' option. This might help you to avoid spending a lot of time learning (or turning off) new Vim 'features' as they crop up with every release...

echo :set compatible > ~/.vimrc

from within Vim you can check to see the current status of the compatible option...

:verbose set compatible?

this will also indicate indicate what specific configuration file the option was set from

@vognition

This comment has been minimized.

Copy link

@vognition vognition commented May 11, 2018

Thank you

@lijonnas

This comment has been minimized.

Copy link

@lijonnas lijonnas commented May 29, 2018

Thanks vm!

@pvint

This comment has been minimized.

Copy link

@pvint pvint commented Jun 12, 2018

I always forget how to do this and whenever I do a fresh install on a Raspberry Pi I hit this and this is my go-to quick reference.
Thanks!

@virgilioneto

This comment has been minimized.

Copy link

@virgilioneto virgilioneto commented Jun 18, 2018

Thanks!!

@kogorman

This comment has been minimized.

Copy link

@kogorman kogorman commented Jun 28, 2018

It's not so much that I want a Vi experience, although I learned editing with Vi starting around 1985. I don't want compatible mode, for sure. But when I'm editing in a terminal I want to be able to use the mouse to highlight things without getting Vim involved, so that I can copy/paste to other apps.

I have never intentionally used visual mode in vim, and am uncertain why I ever would.

@jaimet561

This comment has been minimized.

Copy link

@jaimet561 jaimet561 commented Sep 5, 2018

What to do if you installed VIM 8 by source?
Which, currently is my situation. I installed VIM 8 by source. How can i disable Visual mode on mouse select?
I do not have ~/.vimrc

@kurisushouri

This comment has been minimized.

Copy link

@kurisushouri kurisushouri commented Sep 5, 2018

jaimet561, if you don't have ~/.vimrc, do the following:

touch ~/.vimrc
echo "set mouse-=a" > ~/.vimrc
source ~/.vimrc

What this does is creates the .vimrc file in your home directory, overwrites the (empty) file with the echo statement, and sources the file to load the contents (makes it take effect).

@jaimet561

This comment has been minimized.

Copy link

@jaimet561 jaimet561 commented Sep 5, 2018

kurisushouri, thanks bro. Thank you so much.

@mrkeuz

This comment has been minimized.

Copy link

@mrkeuz mrkeuz commented Sep 6, 2018

Thanks!

@minac

This comment has been minimized.

Copy link

@minac minac commented Sep 7, 2018

thank you!

@aPollO2k

This comment has been minimized.

Copy link

@aPollO2k aPollO2k commented Oct 4, 2018

Lol simple and powerfull. Thanks.

@nachopro

This comment has been minimized.

Copy link

@nachopro nachopro commented Oct 13, 2018

Vielen dank!

@michield

This comment has been minimized.

Copy link

@michield michield commented Oct 17, 2018

brilliant, thanks

@vitorlui

This comment has been minimized.

Copy link

@vitorlui vitorlui commented Nov 9, 2018

You got a place in the heaven!

@rexave

This comment has been minimized.

Copy link

@rexave rexave commented Nov 17, 2018

many thanks, hate this "feature" !!

@sarevok-anchev

This comment has been minimized.

Copy link

@sarevok-anchev sarevok-anchev commented Dec 16, 2018

Whoever thought this was a sane default ....

Thanks for the solution!

@chris-gillatt

This comment has been minimized.

Copy link

@chris-gillatt chris-gillatt commented Jan 5, 2019

Make sure you add the same entry as the root user too, otherwise when you sudo you'll go back to Old Kent Road.

@jenlampton

This comment has been minimized.

Copy link

@jenlampton jenlampton commented May 15, 2019

100 thanks!

@pantuts

This comment has been minimized.

Copy link

@pantuts pantuts commented May 24, 2019

Now im sane! THanks!

@aivanzipper

This comment has been minimized.

Copy link

@aivanzipper aivanzipper commented May 29, 2019

Thank You!

@jansmets

This comment has been minimized.

Copy link

@jansmets jansmets commented Jun 3, 2019

This visual mode is just awful. Please disable it !

@oioiben

This comment has been minimized.

Copy link

@oioiben oioiben commented Jun 13, 2019

echo "set mouse-=a" >> ~/.vimrc

@arthurdamm

This comment has been minimized.

Copy link

@arthurdamm arthurdamm commented Jun 21, 2019

Also, thank you!

@debugger2

This comment has been minimized.

Copy link

@debugger2 debugger2 commented Jul 9, 2019

THKS!

@ade951

This comment has been minimized.

Copy link

@ade951 ade951 commented Aug 7, 2019

Yes, thanks so much. ssh vi copy/paste was almost impossible for me without this change.

+1.
And the reverse operation is issuing :set mouse+=a

@kirklatslalom

This comment has been minimized.

Copy link

@kirklatslalom kirklatslalom commented Aug 14, 2019

Whoever thought this was a sane default ....
I always forget how to do this and whenever I do a fresh install on ...
This issue was driving me nuts.
+1

Thanks!

@cpu100

This comment has been minimized.

Copy link

@cpu100 cpu100 commented Aug 26, 2019

Oh no, the theme color is gone too.

@cpu100

This comment has been minimized.

Copy link

@cpu100 cpu100 commented Aug 26, 2019

syntax enable
set mouse-=a 
@huaius

This comment has been minimized.

Copy link

@huaius huaius commented Sep 5, 2019

Helped a lot!

@tehsunnliu

This comment has been minimized.

Copy link

@tehsunnliu tehsunnliu commented Sep 10, 2019

syntax enable
set mouse-=a

Thanks. Only setting mouse-=a removed syntax.
Also, backspace stopped working.

set bs=2

@ghuls

This comment has been minimized.

Copy link

@ghuls ghuls commented Sep 30, 2019

To use normal mouse behavior when this option is enabled, press SHIFT while pressing mouse buttons.

@kasumiru

This comment has been minimized.

Copy link

@kasumiru kasumiru commented Oct 28, 2019

In all docker, in all users on all servers
*sad kitty

@UweHeber

This comment has been minimized.

Copy link

@UweHeber UweHeber commented Nov 16, 2019

Many thanks for this tipp

@mxbrandi

This comment has been minimized.

Copy link

@mxbrandi mxbrandi commented Nov 25, 2019

To use normal mouse behavior when this option is enabled, press SHIFT while pressing mouse buttons.

This was valuable info for me.

I also hate the visual mode when selecting text with the mouse, however, the fact that the cursor can be moved with mouse clicks is a good feature imo.

@wapeter

This comment has been minimized.

Copy link

@wapeter wapeter commented Dec 2, 2019

very useful! some Linux installation pre-install vim with mouse visual mode automatically turn ON
indeed, it was a nightmare, cannot copy by the Terminal.

@pturley0

This comment has been minimized.

Copy link

@pturley0 pturley0 commented Dec 19, 2019

Thank goodness Google found this for me.

@alogoc

This comment has been minimized.

Copy link

@alogoc alogoc commented Dec 28, 2019

I have no idea why some sources chose to have this behavior by default but it is clearly driving people crazy.
Thank you for this post!

@maatthc

This comment has been minimized.

Copy link

@maatthc maatthc commented Jan 5, 2020

Creating your own ~/.vimrc will change much more than the mouse behaviour as Vim will not load its default config file.
I rather change the Vim default configuration to only disable the automatic visual mode and keep the rest as it is.
Do do so, first find which files Vim is using as default - just add the option '-D' and Vim will start on DEBUG mode. e.g. :
$ vi -D my-file.js
It will open a prompt and show which config file Vim is reading. e.g. :
Entering Debug mode. Type "cont" to continue.
/usr/share/vim/vimrc
line 8: runtime! debian.vim
>

In this case Vim is reading the file '/usr/share/vim/vimrc' at startup . But that is not the file we are after.
In the prompt, enter 'next' and Vim will show you which command on which line from which file it is executing.
Keep pressing Enter until you see a file called 'defaults.vim' - copy the file location. Enter 'exit' to exit the prompt.
Edit the 'defaults.vim' (in my case is "/usr/share/vim/vim81/defaults.vim").
Add 'set mouse-=a' to the end of the file.

@meilin96

This comment has been minimized.

Copy link

@meilin96 meilin96 commented Jan 9, 2020

This save my life

@mehov

This comment has been minimized.

Copy link

@mehov mehov commented Jan 11, 2020

Creating your own ~/.vimrc will change much more than the mouse behaviour as Vim will not load its default config file.
I rather change the Vim default configuration to only disable the automatic visual mode and keep the rest as it is.
Do do so, first find which files Vim is using as default - just add the option '-D' and Vim will start on DEBUG mode. e.g. :
$ vi -D my-file.js
It will open a prompt and show which config file Vim is reading. e.g. :
Entering Debug mode. Type "cont" to continue.
/usr/share/vim/vimrc
line 8: runtime! debian.vim
>

In this case Vim is reading the file '/usr/share/vim/vimrc' at startup . But that is not the file we are after.
In the prompt, enter 'next' and Vim will show you which command on which line from which file it is executing.
Keep pressing Enter until you see a file called 'defaults.vim' - copy the file location. Enter 'exit' to exit the prompt.
Edit the 'defaults.vim' (in my case is "/usr/share/vim/vim81/defaults.vim").
Add 'set mouse-=a' to the end of the file.

@maatthc Wow, that's a very good point, thank you!

I need this setting changed from a script, so can't have it look for the path manually. Do you think something like this would be safe to use?

DEFAULTSVIM=$(find /usr  -path "*/vim/*" -type f -name "defaults.vim")
sed -i "s/^\"* *set mouse[^$]*/set mouse-=a/" $DEFAULTSVIM
@maatthc

This comment has been minimized.

Copy link

@maatthc maatthc commented Jan 13, 2020

DEFAULTSVIM=$(find /usr  -path "*/vim/*" -type f -name "defaults.vim")

Hi @mehov, if you need to automate it, I reckon a better approach would be use the output of 👍 vim --version.
e.g. Version 8:
system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" defaults file: "$VIMRUNTIME/defaults.vim" fall-back for $VIM: "/usr/share/vim"
e.g. Version 7:
system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" user exrc file: "$HOME/.exrc" fall-back for $VIM: "/usr/share/vim"
There I imagine that if there is no "defaults file" you can use the "system vimrc file", falling back to the default "fall-back for $VIM" in case $VIM is not defined.

@bryanheinz

This comment has been minimized.

Copy link

@bryanheinz bryanheinz commented Jan 25, 2020

another way would be to create the ~/.vimrc file and source the default vim file.

vi ~/.vimrc

source /usr/share/vim/vim81/defaults.vim
set mouse-=a

this gives you the benefit of sourcing the original config, but letting you safely override the defaults. you'll still have to update the source when vim changes version folders.

@ashledombos

This comment has been minimized.

Copy link

@ashledombos ashledombos commented Feb 5, 2020

To use normal mouse behavior when this option is enabled, press SHIFT while pressing mouse buttons.

WOW! Thanks for this @ghuls :)

@lego12239

This comment has been minimized.

Copy link

@lego12239 lego12239 commented Mar 23, 2020

Thanks!

@tanero

This comment has been minimized.

Copy link

@tanero tanero commented May 26, 2020

great and easy solution.

@gardner

This comment has been minimized.

Copy link

@gardner gardner commented Jul 14, 2020

Thanks! I don't understand why this is a default in neovim.

@damnms

This comment has been minimized.

Copy link

@damnms damnms commented Jul 18, 2020

this is what happens when a dev thinks "i think thats a good feature", instead of first asking what the customers think ;)

@vinay1591

This comment has been minimized.

Copy link

@vinay1591 vinay1591 commented Jul 23, 2020

Thanks a lot! Lot of love.

@yogi8091

This comment has been minimized.

Copy link

@yogi8091 yogi8091 commented Jul 30, 2020

Thanks Folks... Made the day...Finally my struggle is over.

@thakurashwani1983

This comment has been minimized.

Copy link

@thakurashwani1983 thakurashwani1983 commented Sep 2, 2020

Thanks for this solution. it worked for me

@CMoH

This comment has been minimized.

Copy link

@CMoH CMoH commented Sep 24, 2020

Finally! The way debian set this up seems like they really want us to use their options

@ngosang

This comment has been minimized.

Copy link

@ngosang ngosang commented Oct 2, 2020

Thank God!!!

@MaMrEzO

This comment has been minimized.

Copy link

@MaMrEzO MaMrEzO commented Oct 9, 2020

This way ends with text copied to clipboard with line numbers, Of course if you have one window vertically.
Instead I used to this option.
JUST HOLD SHIFT KEY DURING SELECTING TERMINAL TEXT TO BEHAVE LIKE set mouse-=a

@pappu687

This comment has been minimized.

Copy link

@pappu687 pappu687 commented Oct 29, 2020

This way ends with text copied to clipboard with line numbers, Of course if you have one window vertically.
Instead I used to this option.
JUST HOLD SHIFT KEY DURING SELECTING TERMINAL TEXT TO BEHAVE LIKE set mouse-=a

In MacOSX with Iterm2, you would use ALT key instead of SHIFT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.