I'm using the following command to copy all lines of text in a document to the system clipboard:
%y+
Usually, especially in order to copy code to StackOverflow ;), I apply a sed transformation to my buffer in order to make it easier to paste in with MarkDown:
%s:^:\t:g
Is there a way to chain the commands without actually applying it to my buffer, only to the copied text?
I suggest using a CLI utility to put it on the clipboard: there are several I found previously, but here's one:
So you'd do
:%!sed 's:^:\t:g`|xclip
or
:%!sed 's:^:\t:g`|xclip -selection c
the latter uses the X clipboard instead of the primary clipboard (assuming UNIX).
On windows, there are likely similar utilities
Edit
A pure vim solution would be:
:let @+=substitute(join(getbufline("%", 1, "$"), "\r\n"), "^\\|\n", "\&\t", "g")
Notes:
If you do not mind adding an entry to the undo list (that means actually editing contents of the buffer), you can perform substitution, yank the text, and undo that substitution in one command.
:%s/^/\t/|%y+|u
Another solution would be to make the substitution right in the contents of
the +
register just after copying.
:%y+|let@+=substitute(@+,'^\|\n\zs','\t','g')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With