0

I often copy to clipboard into other programs (changed to <leader>y)

is there a way to copy to the clipboard and delete once copied in one command?

For example, I want to press <leader>y, copy to clipboard then that line is deleted from vim.

5
  • 1
    What about just d? It's called "delete", but it actually cuts the contents to the clipboard
    – husB
    Apr 20 at 3:37
  • Hi @husB - it deletes with d but I cannot copy that content to outside programs.
    – Vinn
    Apr 20 at 3:45
  • You could use "*d to cut to the system clipboard or make sure the systeme clipboard is used by default by having :set clipboard=unnamed Apr 20 at 4:15
  • @Vinn, Ah, I see your edit now. I previously read "<leader>y" as "y", as the "<leader>" was treated as a html tag and was gobbled up. I have now edited your question accordingly, surrounding it with backticks. What is your mapping for <leader>y? Perhaps we can modify it for a delete mapping.
    – husB
    Apr 20 at 4:59
  • apologies for the confusion. I didnt realise leader didn't show up in brackets @husB
    – Vinn
    Apr 20 at 7:04

1 Answer 1

2

Assuming you have set your copy with something like:

nnoremap <leader>y "+y

You can map "cut" to:

nnoremap <leader>d "+d

PS, it might be worth it to also map visual mode too:

nnoremap <leader>y "+y
xnoremap <leader>y "+y
nnoremap <leader>d "+d
xnoremap <leader>d "+d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.