Disabling mouse support in `vim` in a `gnome-terminal` environment

gnomegnome-terminalmousevim

Edit: The problem of an enabled mouse in vim appears to be specific to gnome-terminal (version 3.4.1.1-1; I am using gnome 3 fallback mode). If I run xterm, mouse support in vim is disabled by default, and I have the option to enable it (:set mouse=a, which I never do) and disable it (:set mouse=). In contrast, when I run vim in gnome-terminal, mouse support is enabled by default and it is not possible to disable it (:set mouse= has no effect). Is there a solution short of changing terminal emulator?


I want to completely disable mouse support in vim. I am running vim version 2:7.3.547-3 through gnome-terminal version 3.4.1.1-1. The following commands, whether executed directly in vim or added to my .vimrc file, fail to disable mouse support:

set mouse =
set mouse =""

Based on reading the vim manual and posts online, one or both of these commands should work. In particular, the vim manual states the following

'mouse'                 string  (default "", "a" for GUI, MS-DOS and Win32)
    The mouse can be enabled for different modes:
            n       Normal mode
            v       Visual mode
            i       Insert mode
            c       Command-line mode
            h       all previous modes when editing a help file
            a       all previous modes
            r       for |hit-enter| and |more-prompt| prompt 
    Normally you would enable the mouse in all four modes with: >
            :set mouse=a
    When the mouse is not enabled, the GUI will still use the mouse for
    modeless selection.  This doesn't move the text cursor.

I am using a laptop and each time my hand brushes the trackpad, my cursor position in vim moves abruptly.

Best Answer

I've found what cause this bad behavior with many linux flavors :

/usr/share/vim/vim80/defaults.vim # may be "vim81" depending on your vim version

it's 'sourced' if there's no ~/.vimrc but even if you have a /etc/vimrc or such /etc file, so if you don't have one just create a blank one as suggested by @lgpasquale:

mkdir ~/.vim/; [[ -s ~/.vim/vimrc ]] && echo "aborted, file exists" || :> ~/.vim/vimrc

If you liked the other features (like syntax highlighting) that you got from defaults.vim, you can use this command rather the the previous one:

mkdir ~/.vim/; [[ -s ~/.vim/vimrc ]] && echo "aborted, file exists" || echo -e "source /usr/share/vim/vim80/defaults.vim\nset mouse=" > ~/.vim/vimrc
Related Question