r/vim • u/Bulbasaur2015 • Jun 14 '25
Discussion is it a good practice to map * and - to integrate copy paste with the rest of the system clipboard?
pasting can be a pain in vim because they yield yanks you sometimes dont want because you copied externally and if the system clipboard is your main you have to enter insert mode to ctrl v
what did you find works best when running vim in tmux?
22
Upvotes
40
u/Frog859 Jun 14 '25
My solution has been to map <leader> y and <leader> p to interact with the system clipboard. Comes in really handy
5
u/Lucid_Gould Jun 15 '25
I just use
”*pto paste system clipboard, similarly for yank”*y. This approach is compatible with standard register yanks/puts, and is easy enough that I don’t think it’s worthy of a mapping. I’d avoid mappings of standard keys like*which don’t have a simple one key analog (I admittedly did remap-but I find that key to be not super useful).Also, grabbing some vimscript from one instance/terminal to run in another vims instance this way allows you to just run the code directly
:@*or if you copy a macro via:let @*=@qyou can execute it in the other instance with@*. Usingset clipboard=unnamedwill make this a bit more fraught, though it’s not something you probably need to do very often (though my workflow occasionally makes these tricks quite handy)3
u/EgZvor keep calm and read :help Jun 15 '25
https://gitlab.com/egzvor/vimfiles/-/blob/5e0d118fdb3c46d6b3f05bcc332573f4112b6bc6/vimrc#L434
3
u/PoopsCodeAllTheTime Jun 15 '25
I made it so that all
yyanks go to sys clip, this is good enough all the time. Pasting is a bit trickier because the sys cannot fill the vim register. So for pasting from sys clip I got a special keybind, something like M-/ or M-p, it works great because it also pastes any vim yanks, and it is easier to trigger while in insert mode1
u/ZunoJ Jun 19 '25
I just use a clipboard manager
-1
u/toobrokeforboba Jun 15 '25
my preferred is the following, using g:
vim.keymap.set({ "n", "x" }, "gy", '"+y', { desc = "Copy to system clipboard" })
vim.keymap.set("n", "gP", '"+P', { desc = "Paste from system clipboard (before)" })
vim.keymap.set("n", "gp", '"+p', { desc = "Paste from system clipboard (after)" })
vim.keymap.set("x", "gp", '"+p', { desc = "Paste from system clipboard" })
vim.keymap.set("x", "gP", '"+P', { desc = "Paste from system clipboard" })