Don't yank when overwriting placeholders

Asked by declassified

When I overwrite a placeholder in UltiSnips, it gets yanked. With my configuration (set clipboard=unnamed
), that overwrites the system clipboard, which can be kind of annoying...is there a way to change this behaviour?
Thank you!

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
declassified
Solved:
Last query:
Last reply:
Revision history for this message
SirVer (sirver) said :
#1

:help autoselect

I think we could probably disable it inside a snippet, but that would feel weird too. Can you try the following: disable it in jump_forward and reenable it on cursormovedi - maybe that works.

otherwise you must change the autoselect option away.

Revision history for this message
declassified (declassified) said :
#2

I'm not sure if I understand what you mean...But my "clipboard" option doesn't contain "autoselect" (or "autoselectplus"). As I wrote above, it only contains "unnamed".

My "guioptions" don't contain "a" or "A".

Revision history for this message
SirVer (sirver) said :
#3

I do not know where this behavior is coming from then. Ultisnips does not yang anything - if vim yanks everything you select into the clipboard too than you have to figure out which feature is enabling this - my Vim does not do that and I have definitely not explicitly disabled this. If you find this out, we can think if we can disable it inside snippets (though I am not positive that this works in an unobtrusive fashion).

Revision history for this message
declassified (declassified) said :
#4

Hm that's weird...I removed all my plugins except for UltiSnips, and trimmed my .vimrc to a bare minimum:

_____________________________
set nocompatible

filetype off
execute pathogen#infect()
filetype plugin indent on
set hidden
set clipboard=unnamed
set guioptions-=a
_____________________________

It's still the same behaviour described above...

I'm using MacVim snapshot 71 (which is Vim 7.4.22).

Revision history for this message
SirVer (sirver) said :
#5

What happens if you manually select something in visual mode (i.e. not with ultisnips jump). Is this copied to your clipboard too?

I doubt that UltiSnips is the culprit here.

Revision history for this message
declassified (declassified) said :
#6

No, it doesn't get copied. Even in UltiSnips, just selecting something doesn't copy it. As I wrote in the original post, overwriting the placeholder copies it.
If I insert a snippet it marks a placeholder text. If I then press ESC, the clipboard is untouched. Once I overwrite the placeholder, though, it gets copied.

By the way, it's the same behaviour on the older MacVim (i.e. Vim 7.3).

I'm a programmer myself, so I can relate to the feeling that the problem must be outside...but with an almost empty .vimrc, no other plugins apart from UltiSnips, and on two different Vim version, I'm not sure what else could be the culprit..

Revision history for this message
SirVer (sirver) said :
#7

:) Well, I am using practically the same setup (MacVim) and I cannot reproduce the problem with the lean setup you describe. But I think the set clipboard=unnamed could be the culprit. From the Vim help clipboard-unnamed:

When included, Vim will use the clipboard register '*' for all yank, delete, change and put operations which would normally go to the unnamed register.

You overwrite selected text when you overwrite the tabstop, so it seems likely that this text goes to the * which is the system clipboard - one could argue if this is a bug or not.

Why do you set this option even?

Revision history for this message
declassified (declassified) said :
#8

I want Vim to use the system clipboard whenever it's yanking something. But just for fun :) Let's remove that line from .vimrc, so we have just this:
_______________________
set nocompatible

filetype off
execute pathogen#infect()
filetype plugin indent on
set hidden
set guioptions-=a
_____________________________
And UltiSnips is the only plugin.

Open a new blank buffer and press:
iHello<Esc>yyp
The document now contains two lines with "Hello" on each of them. So "Hello" was in the unnamed register. Now press:
oBOX<Tab>test<Esc>Gp
Pressing "p" put the text "content" instead of "Hello". So UltiSnips overwrote the unnamed register.

Do you get the same behaviour?

Revision history for this message
SirVer (sirver) said :
#9

yes, I get the same behaviour, but this is no bug, it is Vim's default behavior. Try it out:

visual select some text -> <c-g> (this inserts select mode, which means typing will overwrite your current selection) -> now type.
the overwritten text will end up in the unnamed buffer.

Revision history for this message
declassified (declassified) said :
#10

Ah okay, I have looked further into select mode, and there doesn't seem to be a way to change how it's overwriting the unnamed register...

I've now gotten the wanted behaviour by removing the clipboard=unnamed and instead doing this:
_______________________
vnoremap p "*p
nnoremap p "*p
nnoremap P "*P
nnoremap y "*y
vnoremap y "*y
nnoremap yy "*yy
_______________________

Sorry for taking your time! I still have to learn a lot about Vim :)

Revision history for this message
SirVer (sirver) said :
#11

no problem, just glad that the problem is not in ultisnips.