2

Just installed the surround.vim plugin and some of the commands don't work as expected. I am using this question as an example

This is a lo*ng line and I want to highlight two words

a ys2aw" should change the above to

This is a "long line" and I want to highlight two words

but for me it changes it to

This is a g and I want to highlight two words

Other times it has no affect at all! I think it has to do with what is in the yanked register.

When I am typing ys, in the bottom right I can see that it quickly changes to g@

Finally, I am pretty sure no other plugins are interfering as by issuing the verbose map yss command:

 n  yss           <Plug>Yssurround
    Last set from ~/.vim/plugin/surround.vim                                                                                                                     
 n  ys            <Plug>Ysurround
    Last set from ~/.vim/plugin/surround.vim

Does anyone know what is going wrong here?

Community
  • 1
  • 1
puk
  • 16,318
  • 29
  • 119
  • 199
  • Sorry, I can't reproduce the bug. Where exactly do you have your cursor? On the `o` or on the `n`? – romainl Oct 03 '12 at 20:25
  • @romainl I just tried it again over the "o". If I yank it into vim, go over the "o" and issue the command `ys2aw"` I get: `This is a "This is a "long line" and I want to highlight two words" and I want to highlight two words ` – puk Oct 03 '12 at 20:29
  • @romainl if I undo and issue the command again, I get the same behavior, but with a new line before and after the pasted inside quote. If I then undo and redo yet again, nothing appears to change (although the file is listed as being modified) – puk Oct 03 '12 at 20:32
  • 1
    @romainl I think I figured it out, in my vim file I have set it such that gnome and vim use the same clipboard (`set clipboard=unnamedplus`) and commenting this out removes the problem so I guess surround uses the unnamed register somehow. – puk Oct 03 '12 at 20:39

1 Answers1

1

I figured it out, to make it easier to copy/paste between vim and, well, everything else, I had the following rule in my .vimrc file:

set clipboard=unnamedplus

This makes surround.vim behave incorrectly. Instead what I did was add the following line to my .vimrc file to allow me to toggle this desired behaviour on/off

nnoremap <leader>hf :set clipboard=unnamedplus<CR>
nnoremap <leader>fh :set clipboard-=unnamedplus<CR>

and now surround.vim works as normal

puk
  • 16,318
  • 29
  • 119
  • 199
  • Crap! I'm very sorry: I experienced a similar problem a long time ago and solved it exactly like that. I should have remembered. – romainl Oct 03 '12 at 21:03
  • Please report this to the plugin's author (i.e. open a GitHub issue); many plugins temporarily reset `'clipboard'` to avoid such interference. – Ingo Karkat Oct 04 '12 at 08:05