TERM=xterm enables mouse mode in vi, breaks pasting with middle mouse

Bug #1661691 reported by Scott Moser on 2017-02-03
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
vim (Ubuntu)
High
Adam Conrad
Zesty
High
Adam Conrad

Bug Description

I quite often have the following work flow:

a.) lxc launch ubuntu-daily:zesty z1
b.) lxc exec z1 /bin/bash
c.) % vi foo.txt
d.) paste some thing from my X buffer (hit middle mouse button).

Somewhere between yakkety (2:7.4.1829-1ubuntu2.1) and zesty (2:8.0.0095-1ubuntu2) this behavior changed.

Previously this all worked fine.

Now, in zesty, however an attempt to paste results in a vi error message:
 E353: Nothing in register "

to fix this, you can first disable the mouse 'a' [1]

 : set mouse-=a

I'm not sure what is enabling this, because /usr/share/vim/vimrc has the line
set mouse=a commented out.

--
[1] http://www.varesano.net/blog/fabio/disable%20vim%20automatic%20visual%20mode%20using%20mouse

ProblemType: Bug
DistroRelease: Ubuntu 17.04
Package: vim-nox 2:8.0.0095-1ubuntu2
ProcVersionSignature: Ubuntu 4.9.0-12.13-generic 4.9.2
Uname: Linux 4.9.0-12-generic x86_64
NonfreeKernelModules: zfs zunicode zavl zcommon znvpair
ApportVersion: 2.20.4-0ubuntu1
Architecture: amd64
CurrentDesktop: Unity
Date: Fri Feb 3 12:14:20 2017
EcryptfsInUse: Yes
InstallationDate: Installed on 2015-07-23 (561 days ago)
InstallationMedia: Ubuntu 15.10 "Wily Werewolf" - Alpha amd64 (20150722.1)
SourcePackage: vim
UpgradeStatus: No upgrade log present (probably fresh install)

Scott Moser (smoser) wrote :
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in vim (Ubuntu):
status: New → Confirmed
LaMont Jones (lamont) wrote :

A very unexpected, and totally unwelcome change to vim.

LaMont Jones (lamont) wrote :

Also true when TERM=screen -- I suspect it doesn't care what terminal you're using, if it can grab mouse events, it does.

Scott Moser (smoser) wrote :

Well, its not *anything*. setting term to the following allow you to paste normally:
 TERM=ansi
 TERM=vt220
 TERM=vt100
 TERM=pcansi

Changed in vim (Ubuntu Zesty):
importance: Undecided → High
Adam Conrad (adconrad) wrote :

I can middle-paste fine under TERM=xterm with vim. Are you using gvim or some other variant?

Happening to me as well with TERM=xterm
Vim is set to "/etc/alternatives/vim -> /usr/bin/vim.basic", so "most normal" vim, no gvim or such.

Workarounds:
Note: inserting with "shift+insert" still gets the content of the mouse buffer you wanted to paste with the middle-button. Sometimes faster than disabling mouse.

Even more comfortable is this (from vim help):
        Note: When enabling the mouse in a terminal, copy/paste will use the
        "* register if there is access to an X-server. The xterm handling of
        the mouse buttons can still be used by keeping the shift key pressed.
        Also see the 'clipboard' option.

And I can confirm that with shift pressed middle-button paste as well as "mark to copy" works as it did in the past.

Note the diff in the default at least on the Help:

Yakkety:
'mouse' string (default "", "a" for GUI, MS-DOS and Win32)
                        global
                        {not in Vi}

Zesty:
'mouse' string (default "", "a" for GUI, MS-DOS and Win32,
                                                 set to "a" in defaults.vim)
                        global
                        {not in Vi}

That matches: https://github.com/vim/vim/blob/master/runtime/defaults.vim

From the NEWS file on the last version:
vim (2:8.0.0022-1) unstable; urgency=medium

  Vim now ships with a defaults.vim file which, when the user has no vimrc,
  enables some options that have historically been disabled by default. This
  is described in more detail at ":help defaults.vim".

  Since defaults.vim is loaded when the user's vimrc would typically be
  loaded, it will override any settings in /etc/vim/vimrc(.local). In order
  to disable the loading of defaults.vim, add

    let g:skip_defaults_vim = 1

  to /etc/vim/vimrc(.local).

 -- James McCoy <email address hidden> Tue, 04 Oct 2016 20:28:02 -0400

That is the new file we deliver "doing" this:
egrep 'mouse=' -C 3 /usr/share/vim/vim80/defaults.vim
" In many terminal emulators the mouse works just fine. By enabling it you
" can position the cursor, Visually select and scroll with the mouse.
if has('mouse')
  set mouse=a
endif

Probably the fastest, least interactive check on this via lxd containers:

$ lxc exec yakkety-test -- /bin/sh -c 'rm -f viconf 2>/dev/null; vim -c "mkv viconf|q"; grep -q mouse viconf'

$ lxc exec zesty-tests -- /bin/sh -c 'rm -f viconf; vim -c "mkv viconf|q"; grep mouse viconf'
set mouse=a

With a cat instead of a grep you can see that much more changed than just the mouse - well it is major version bump to 8.0.

P.S. Thank you scott for filing this, it annoyed me a while but I never bothered to look deeper.
Personally I'll likely go with the "hold shift" for now and wait for a discussion here.

Adam Conrad (adconrad) wrote :

Ahh, thanks for digging, Christian. Given this appears to break horribly in all chroot scenarios (not just containers), I'm inclined to just remove that bit from the defaults file. Also of note, the shiny new defaults thing has syntax:on, so I can remove that from our Debian delta. Yay. Will prepare an upload fixing this and some other bits shortly.

Adam Conrad (adconrad) on 2017-03-17
Changed in vim (Ubuntu Zesty):
assignee: nobody → Adam Conrad (adconrad)
status: Confirmed → In Progress
Scott Moser (smoser) wrote :

Adam,

I'm not sure that we should pick up delta for this. If upstream vim and upstream debian both enabled this new behavior, we may just want to accept it. Once you learn about 'shift', then i think its acceptable.

Additionally, any one who writes their own vimrc (like you or I or ubuntu developers) are going to not see this issue... which is why we only saw it in a container, and I never even noticed it in a ssh vm because I have user-data that sets up .vimrc there.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package vim - 2:8.0.0095-1ubuntu3

---------------
vim (2:8.0.0095-1ubuntu3) zesty; urgency=medium

  * debian/patches/ubuntu-mouse-off.patch: Revert enabling mouse mode by
    default in defaults.vim, breaks in chroots/containers (LP: #1661691)
  * debian/rules: Fix merge error that regressed python3 support in vim.

 -- Adam Conrad <email address hidden> Fri, 17 Mar 2017 06:13:35 -0600

Changed in vim (Ubuntu Zesty):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers