News for hackers. Stuff that matters.
Re:The weight of the clipboard by gorgoiler on Wednesday January 05, 2022 @02:28AM (#29806164)
Unify your vim clipboard with the system clipboard, they said. The integration is wonderful, they said.

Well:

1/ copy URL from browser

2/ alt tab to vim notes

3/ delete old URL from notes

4/ paste new URL but get the old URL instead?!

How do I do the FORTH equivalent of swapping the two items on the top of the stack (and have a stack in the first place)? :)

Re:The weight of the clipboard by avnigo on Wednesday January 05, 2022 @03:31AM (#29806551)
> 4/ paste new URL but get the old URL instead?!

To paste the copied URL instead of the deleted one, you can paste from the 0 register by using "0p.

Otherwise, depending on your system, pasting from the * or + registers (using "*p or "+p) will paste what you copied from the browser.

Re:The weight of the clipboard by stavros on Wednesday January 05, 2022 @05:51AM (#29807487)
For me, the two things don't go to the same register, but for you, you can select the old URL and paste over it (vWp) instead of deleting and then pasting (dvWP).
Re:The weight of the clipboard by spectaclepiece on Wednesday January 05, 2022 @03:01AM (#29806357)
After reading this my mind went to the same place of viewing the clipboard as a stack. Wonder if that’s possible system-wide.

One solution I have in vim which I always forget to use is adding an additional d or p to use a secondary paste buffer:

vnoremap dd "ad

nnoremap ddd "add

nnoremap pp "ap

Re:The weight of the clipboard by avnigo on Wednesday January 05, 2022 @03:35AM (#29806571)
You can also move lines up and down using the move command:

  :[range]m[ove] {address}
Some common remaps:

  vnoremap <c-j> :m '>+1<CR>gv=gv
  vnoremap <c-k> :m '<-2<CR>gv=gv
  inoremap <c-j> <Esc>:m .+1<CR>==gi
  inoremap <c-k> <Esc>:m .-2<CR>==gi
  nnoremap <leader>j :m .+1<CR>==
  nnoremap <leader>k :m .-2<CR>==
Re:The weight of the clipboard by _dain_ on Wednesday January 05, 2022 @07:09AM (#29807991)
I got really annoyed by this, so made it so dd just deletes rather than adding to clipboard. If I really want to "cut" I highlight in visual select mode and press x.

Having the common deletion operation also default to adding to clipboard is a design mistake in Vim, I feel.

Re:The weight of the clipboard by julesnp on Wednesday January 05, 2022 @10:30AM (#29810165)
If you don't need the old URL, I'd recommend this plugin:

https://github.com/inkarkat/vim-ReplaceWithRegister

Re:The weight of the clipboard by jarenmf on Wednesday January 05, 2022 @02:57AM (#29806332)
If usually delete to another register to avoid that, "dd for example :)
Re:The weight of the clipboard by normie3000 on Wednesday January 05, 2022 @03:02AM (#29806362)
Doesn’t dd delete the line under the cursor?
Re:The weight of the clipboard by Veen on Wednesday January 05, 2022 @04:45AM (#29807051)
dd deletes the line under the cursor. "dd deletes something into the d register (the " is part of the command that selects the register). "d selects the register. The second d is the delete command. So you could do something like "dd2w to delete the next two words and save them into the d register. The same thing works with any named register, so a less confusing example might have been "cd2w to delete into the c register.
Re:The weight of the clipboard by Tyr42 on Wednesday January 05, 2022 @11:11AM (#29810778)
There's also a dedicated null register "_, so "_d really just deletes it without storing it anywhere. But I agree _ is harder to reach than d.

I also really like junegunn/vim-peekaboo, which really helps if I know I copied something, but I'm not sure how far down the stack it is.

Re:The weight of the clipboard by boondaburrah on Wednesday January 05, 2022 @05:44AM (#29807457)
As a VIM noob for the past 7 years, I've learned many times over that dd is cut (like yy is copy), not delete, despite what people say.
Re:The weight of the clipboard by unionpivo on Wednesday January 05, 2022 @11:11AM (#29810772)
I just go to insert mode and shift-Insert , to insert from clipboard

This works even if I ssh into something.