14

I found plenty of questions regarding disabling visual mode in vim but none that tackles my particular problem:

I added set mouse-=a to my /etc/vim/vimrc file to disable visual mode for good. Thing is: That seems to do nothing. However when I put the exact same directive into my user's .vimrc file it works.

Is this expected behaviour? Did I miss something? Has anyone a solution which doesn't involve managing a .vimrc file for each and every user?

Thanks in advance!

I am on Debian 10, fully updated by the way.

Thorian93
  • 733
  • 2
  • 6
  • 17
  • 3
    What is the output of `:verbose set mouse?` in Vim, when you have `set mouse=-a` in `/etc/vim/vimrc` but not in `~/.vimrc`? Also, does the output of `:scriptnames` include `/etc/vim/vimrc`? – muru Nov 11 '19 at 08:04
  • 1
    Hi, the first command tells me, that it ignores my /etc/vim/vimrc: `mouse=a Last set from /usr/share/vim/vim81/defaults.vim line 79`. For the secont part: No it does not. – Thorian93 Nov 11 '19 at 16:22

3 Answers3

19

Debian's /etc/vim/vimrc contains this comment:

" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
" This happens after /etc/vim/vimrc(.local) are loaded, so it will override
" any settings in these files.
" If you don't want that to happen, uncomment the below line to prevent
" defaults.vim from being loaded.
" let g:skip_defaults_vim = 1

As :verbose set mouse? says, that was set by /usr/share/vim/vim81/defaults.vim mentioned above ($VIMRUNTIME on Debian would be /usr/share/vim/vim<version>).

So, you can either create a ~/.vimrc (or ~/.vim/vimrc) for your user (even an empty one will do), or uncomment let g:skip_defaults_vim = 1 in /etc/vim/vimrc.

muru
  • 69,900
  • 13
  • 192
  • 292
  • That's exactly what I needed, thanks a lot! This has been bugging me for some time and know I understand the behaviour. An interesting way of configuration though. – Thorian93 Nov 12 '19 at 09:02
5

Instead of muru's answer, I just straight edited the default at /usr/share/vim/vim81/defaults.vim (or whatever your vim version is).

Comment out set mouse=a by changing it to "set mouse=a

" is how you comment out stuff in vim config files

This has the benefit of keeping useful stuff in the defaults like syntax highlighting but removing that annoying visual mode

I'm probably gonna get replies that I shouldn't do this because it'll be overwritten when vim updates but it's a quick fix for me now!

georgiecasey
  • 2,441
  • 1
  • 14
  • 5
  • I might miss something, but why don't you do that in `/etc/vim/vimrc`? – Thorian93 Jan 11 '21 at 17:19
  • @Thorian93 I tried that, then I lost all the options from the default file like syntax highlighting. I could very easily be doing something wrong. – georgiecasey Jan 11 '21 at 17:30
  • I see. From what I know up to now the clean way would be to write your own `.vimrc` file with the settings you want. That way you can be sure your settings are correct and they won't be overwritten by package upgrades. – Thorian93 Jan 13 '21 at 17:44
  • 1
    Thank you for this. By adding a ~/.vimrc all the defaults provided by defaults.vim are lost (color coding for example). – Paul Wieland Apr 14 '21 at 14:41
  • Such a change will be overwritten when the package is updated. – muru Aug 24 '21 at 08:54
3
$ cat >.vimrc
source $VIMRUNTIME/defaults.vim
set mouse=
^D
$
James Bowery
  • 131
  • 4