# vim randomly pastes yanked content



## krawall (Sep 28, 2017)

Hi,

I've got a strange problem with editors/vim-lite since I think yesterday (but it could be longer): Sometimes if I open vim it just pastes everything that it has saved from the last yank (copy in vim terms). I'm totally at a loss, why it's doing it. I had the same vim config for almost two years (see below) and never had a problem.

I can't reproduce it except to open vim repeatedly. In about twenty start ups it should paste something at least once. I tried to downgrade (after all I upgraded vim yesterday from 8.0.1115 -> 8.0.1141), but even with an older version than 8.0.1115 it still happens.

Here is my /root/vim/.vimrc

```
syntax on
colorscheme default
set t_Co=16

let g:is_posix = 1

set relativenumber
set fileencodings=utf-8
set nocompatible
set bs=indent,eol,start
set history=50
set ruler
set hlsearch
set modeline
set mouse-=a
```

There is no /root/.vimrc nor /usr/local/etc/vim/vimrc.
It seems to happen at all our servers and it doesn't matter if the opened file exists or not.

editors/vim-lite was build by poudriere with DEFAULT_VIMRC: off

It's a bit scary, especially with single characters that I won't be able to catch every time..


----------



## SirDice (Sep 28, 2017)

A stuck 'p' key perhaps?


----------



## krawall (Sep 29, 2017)

I don't have any other problems with the 'p' or any other key.

I just got another keyboard to try it anyhow but now I can't reproduce it at all. Very strange. I'll leave the other keyboard connected and retry when the problem reappears..


----------



## SirDice (Sep 29, 2017)

krawall said:


> I just got another keyboard to try it anyhow but now I can't reproduce it at all. Very strange. I'll leave the other keyboard connected and retry when the problem reappears..


Maybe the old keyboard is sending spurious keycodes, mimicking the pressing of 'p'. That could explain the seemingly random pastes. But I would have expected that key to popup in the middle of commands too, not only with vim. It's a weird issue, that's for sure.


----------



## krawall (Sep 29, 2017)

Yeah. That's what I thought. The random paste happened again, with both the keyboards.

But this time there wasn't anything yanked so instead of inserting something vim replaced the last character in the first line in the opened file with '2'. Two days ago I also had to fix a /etc/rc.conf that had a '2' instead of a '"' as a last character in the first line..


----------



## SirDice (Sep 29, 2017)

Could you try to use vi(1) instead of vim(1)? That may narrow down the possibilities, vi(1) doesn't read vim(1) configuration files but vim(1) does read vi(1) configs.


----------



## chrbr (Sep 29, 2017)

krawall said:


> set mouse-=a


Is it possible that vim(1) picks something from the UART or something which behaves so? As far as I have seen the mouse should be disabled by default. I did a quick search and have no seen a reference about the syntax above, but I did not seek a lot. May be it is correct, may be not. Therefore it might be worth to confirm the syntax or to try to delete the line.


----------



## ShelLuser (Sep 29, 2017)

Also, are you sure it's a put and not something else?

Reason I ask is because you mentioned that it did this when you just started it. Could it have been loading a previous file or something? (doubt it, but I figured I could always mention this).


----------



## Jeckt (Sep 29, 2017)

I've been using vim for many years, and despite the fact that it's the most frequently updated program I use, I never had any problems until a month or two ago.  While it's solved for me now, when I'd open a file there would be some weird junk inserted at the top I can't recall if it actually changed the file or not.  Versions after 8.0.0962 had this problem for a while, but recently it started working for me. This might be a bug that isn't completely sqashed, so you might want to put in a bug report to the vim people.  If you use portmaster, you might try looking for an older vim package (pre 8.0.1000) saved in /usr/ports/packages/portmaster-backup/


----------



## krawall (Oct 4, 2017)

Hi, sorry, havn't had a lot time this week to take care about this problem. But thank your for all your answers!

SirDice: I'll try vi next time this happens. But are you sure that vim reads vi config files? `:version` only lists:

```
system vimrc file: "/usr/local/etc/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/local/etc/vim"
 f-b for $VIMRUNTIME: "/usr/local/share/vim/vim80"
```

chrbr: I had the same trouble with `mouse=` but I'll try without my vim config file next time this happens. Mouse should be disabled by default but it was briefly enabled half a year ago and it takes time to put this config on ~500 servers / jails (even with ansible), so I'd prefer to keep it this way 

ShelLuser: I can paste the same content in every vim file that it happened to with 'p', also this happens at random..

Jeckt: Thanks for this information, do you have a link to the old bug report? I'm using poudriere, but if this is a vim problem that doesn't goes away I might just switch to neovim..


----------



## SirDice (Oct 4, 2017)

krawall said:


> But are you sure that vim reads vi config files?


That's what I always believed. But looking through the man pages that might indeed not be the case. I was sure that was the case but maybe I'm confusing certain Linux distributions where vi(1) is actually vim(1) in compatibility mode.

But since the yank and paste commands are the same it would still be useful to test if there's a difference.


----------



## Jeckt (Oct 4, 2017)

I don't have a link to any bug report, it's just that I noticed there was a problem and after a few upgrades it went away (and hasn't appeared since), so it seems like someone was aware of the problem.  Since vim can save buffers after files are closed and pate in new ones, I wonder if something isn't activating it in one of those config files.  I know building it with DEFAULT_VIMRC screwed me pretty bad, so I disabled it thereafter. It might be worth trying on a test system if you have one where vim can't find any config files to see if it still happens.


----------



## rigoletto@ (Oct 4, 2017)

You could try editors/neovim instead. It uses different config files; however I am not sure if it try to use editors/vim configs - _but probably not_.


----------



## JohnnySorocil (Oct 7, 2017)

Are you using vim inside tmux session?
I had some problems with tmux mouse scroll which would insert some text (but not from vim's paste buffers) in vim and shell.


----------



## krawall (Oct 11, 2017)

Hi. Sorry for the long delay.

SirDice
After I couldn't reproduce this problem without the vimrc I disabled every config one after another. Strangely enough the colorscheme setting seems to cause the paste.. I would just disable it but here vim loads the 'ron' theme with 256 colors which is not easy on the eyes. The `t_Co=16` setting doesn't seem to help (vim still reports 256 on `:set t_Co?`)
But it doesn't seem to have anything to do with the colorscheme itself. If I put `colorscheme ron` in the vimrc pastes happen. If I leave it out and 'ron' gets loaded by some `vim` magic, everything seems to be fine..

Jeckt


krawall said:


> editors/vim-lite was build by poudriere with DEFAULT_VIMRC: off



JohnnySorocil
Same problem with and without screen. Never using tmux.


----------



## krawall (Oct 12, 2017)

getopt
Yes.

`locale`

```
LANG=de_DE
LC_CTYPE="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_ALL=de_DE.UTF-8
```

`vim --version`

```
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct  9 2017 13:18:27)
Included patches: 1-1178
Compiled by jonas@pkg.vektorrausch.net
Huge version without GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    +mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     -tcl
-balloon_eval    +folding         +mouse_xterm     +termguicolors
-browse          -footer          +multi_byte      +terminal
++builtin_terms  +fork()          +multi_lang      +terminfo
+byte_offset     -gettext         -mzscheme        +termresponse
+channel         -hangul_input    +netbeans_intg   +textobjects
+cindent         +iconv           +num64           +timers
-clientserver    +insert_expand   +packages        +title
-clipboard       +job             +path_extra      -toolbar
+cmdline_compl   +jumplist        -perl            +user_commands
+cmdline_hist    +keymap          +persistent_undo +vertsplit
+cmdline_info    +lambda          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       -python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            -ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      +startuptime     -xpm
+eval            +mouse_dec       +statusline      -xsmp
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_clipboard
+extra_search    -mouse_jsbterm   +syntax          -xterm_save
+farsi           +mouse_netterm   +tag_binary     
   system vimrc file: "/usr/local/etc/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/local/etc/vim"
 f-b for $VIMRUNTIME: "/usr/local/share/vim/vim80"
Compilation: cc -c -I. -Iproto -DHAVE_CONFIG_H   -DLIBICONV_PLUG -I/usr/local/include  -O2 -pipe  -DLIBICONV_PLUG -fstack-protector -fno-strict-aliasing -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: cc   -fstack-protector -L/usr/local/lib -Wl,--as-needed -o vim               -lm -lelf  -lncurses
```


----------



## Snurg (Oct 12, 2017)

Does this problem happen when you use a PS2->USB adapter or an USB keyboard?

I ask because I found out that when using USB for keyboard, some programs somehow tend to get out of sync with the keyboard regarding the escape scancodes etc.
After some research I found out that this seems to happen when USB renegotiates/reconnects.
If you notice that when you experience "strange mysterious keyboard input from nowhere" and find a keyboard reconnect in the logs registered at just that time, you might try out other USB keyboards and/or PS2->USB adapters which might behave better. But as this problem is USB-inherent, I won't expect too much. I guess a true solution would include some refinements in the uhid stack to avoid partial scancodes to be put into the keypress queue.

For me, the most reliable solution was just not to use USB for keyboard, only PS/2 connector on mainboard or docking station.


----------



## Oko (Oct 14, 2017)

krawall said:


> Hi,
> 
> I've got a strange problem with editors/vim-lite since I think yesterday (but it could be longer): Sometimes if I open vim it just pastes everything that it has saved from the last yank (copy in vim terms). I'm totally at a loss, why it's doing it. I had the same vim config for almost two years (see below) and never had a problem.



And that is exactly why vim should not be used when you have the best UNIX editor (nvi) in the base.  Light reading for people who want to learn more

http://galexander.org/vim_sucks.html


----------



## forquare (Oct 14, 2017)

krawall said:


> editors/vim-lite was build by poudriere with DEFAULT_VIMRC: off



Is this the only build option you’ve changed? I wonder if you see the same issue using editors/vim-lite from the FreeBSD repo?



Oko said:


> And that is exactly why vim should not be used when you have the best UNIX editor (nvi) in the base.  Light reading for people who want to learn more
> 
> http://galexander.org/vim_sucks.html



That article is old, and when I tried it a couple of months ago I found I could not reproduce many of the issues seen when using editors/vim-lite

My issue with nvi(1) is that the line numbers take up so much room, and I like having them on by default.


----------



## krawall (Oct 16, 2017)

Snurg 
I've only got USB keyboards. But this seems to be a relatively new problem for me, so I still think that there is some misconfiguration here (or even a bug). Also I don't have a PS connector..

Oko
vim works fine for me on every other os / non work related FreeBSD configuration and I quite like stuff like relative line numbers and syntax highlighting. Also most of this rant isn't true (anymore)..

forquare 
That's the only option for editors/vim-lite 
I get the same problems with vim-lite from the FreeBSD repo.


----------



## rigoletto@ (Oct 16, 2017)

editors/vim-lite is just a editors/vim slave port with all "options" off. See HERE.

If you want to try some different vim, I think the only option is editors/neovim.


----------



## getopt (Oct 16, 2017)

lebarondemerde said:


> with all "options" off.


Not really. Vim-lite is just a version for terminals without gvim for Xorg.


----------



## krawall (Oct 16, 2017)

Not all. But it's more than just gvim disabled, i.e. language bindigs that make vim dependent on their interpreters:

```
.if defined(LITE)
OPTIONS_DEFAULT=        DEFAULT_VIMRC
OPTIONS_SLAVE=          CONSOLE
OPTIONS_EXCLUDE:=       ${OPTIONS_DEFINE:NDEFAULT_VIMRC} \
                        ${OPTIONS_SINGLE_UI:NCONSOLE} \
                        ${OPTIONS_GROUP_LANGBIND}
.endif
```

But DEFAULT_VIMRC is still the only option you can set in theeditors/vim-lite port. I'm not really getting, what you are trying to tell me here lebarondemerde ..


----------



## rigoletto@ (Oct 16, 2017)

krawall

If something fail while using editors/vim it should also fail while using editors/vim-lite, unless the problem is related with something disabled in the -lite version.

So, with you wanna test if the problem is caused by something in your configuration you be better testing it against editors/neovim, to be sure.


----------



## linux->bsd (Dec 7, 2017)

Does it happen when you run vim without scripts?

`vim -u NORC`
or
`vim -u NONE`


----------



## linux->bsd (Dec 7, 2017)

linux->bsd said:


> Does it happen when you run vim without scripts?
> 
> `vim -u NORC`
> or
> `vim -u NONE`



Also, try this: `vim -c "normal qa"`.

That should start vim in recording mode. Then hit `q` to end recording, and `:reg a` to check the contents of register "a." Is there a leading "p" inside that register?

Or run vim in debug mode: `vim -D`.


----------



## dinoex@ (Feb 15, 2018)

I had the same problem as well...

Thanks to people on IRC I have now a workaround:

I put this block in the top of my ~/.vimrc


```
" keep vim in xterm clean
set all&
highlight clear
augroup vimrcEx
autocmd!
augroup END
set mouse=
" local stuff follows ...
```


----------



## Tuttle (Feb 15, 2018)

dinoex@ said:


> I had the same problem as well...
> 
> Thanks to people on IRC I have now a workaround:
> 
> ...



Those settings did not work me. These did:

~/.vimrc

```
set t_RS=                                                                
set t_RC=
set t_SH=
```

I'm not sure if all three are needed, but I have not been able to reproduce the problem with just those three lines added to my ~/.vimrc.


----------



## krawall (Feb 19, 2018)

Sorry, I didn't have much time to figure this out. I've just replaced vim by neovim a couple of weeks ago. No problem there.


----------

