Forem

Sérgio Araújo
Sérgio Araújo

Posted on • Edited on

1

Primary Selection as a Plus

Why Primary Selection?

Most people I see on the Internet, nvim users, usually give up "primary selection" by setting their clipboard to "unnamedplus". Those who use Linux since its beginning like selecting some text and hitting middle mouse button to have the text pasted somewhere else.

If you can have two independent clipboards in your system why do not use it? Because in vim you can just type:

:reg *,+
Enter fullscreen mode Exit fullscreen mode

The primary selection is represented by * and the clipboard by +.

Fix primary selection paste on firefox:

On my awesomeWM I have this code (line 05 to 09):

01 clientbuttons = gears.table.join(
02   awful.button({ }, 1, function (c)
03     c:emit_signal("request::activate", "mouse_click", {raise = true})
04   end),
05   -- paste primary selection Ctrl + button1
06   awful.button({ "Control" }, 1, function (c)
07     c:emit_signal("request::activate", "mouse_click", {raise = true})
08     awful.spawn.with_shell("xdotool click --delay 0 --clearmodifiers 2")
09   end),
10   awful.button({ modkey }, 1, function (c)
11     c:emit_signal("request::activate", "mouse_click", {raise = true})
12     awful.mouse.client.move(c)
13   end),
14   awful.button({ modkey }, 3, function (c)
15     c:emit_signal("request::activate", "mouse_click", {raise = true})
16     awful.mouse.client.resize(c)
17   end)
18 )
Enter fullscreen mode Exit fullscreen mode

Even though I can not middle click on firefox to paste my primary selection I can now hold Ctrl + button1 to have it working again.

Primary Selection on neovim:

local function map(mode, lhs, rhs, opts)
    local options = { noremap = true, silent = true }
    if opts then
        if opts.desc then
            opts.desc = "init.lua: " .. opts.desc
        end
        options = vim.tbl_extend('force', options, opts)
        end
    vim.keymap.set(mode, lhs, rhs, options)
end


-- avoid clipboard hacking security issue
-- http://thejh.net/misc/website-terminal-copy-paste
-- inoremap <C-R>+ <C-r><C-o>+
map("i", "<C-r>+", "<C-r><C-o>+", { desc = 'fix terminal copy paste hack issue' })
map("i", "<S-Insert>", "<C-r><C-o>*", { desc = 'fix terminal copy paste hack issue' })

-- copy to the primary selection on mouse release
map("v", "<LeftRelease>", '"*y' , {silent = true, desc = "Copy selection to primary selection"})
Enter fullscreen mode Exit fullscreen mode

Paste primary selection on bspwm

# %%hotkey: paste primary selection %%
ctrl + alt + ~button1
    xdotool click --delay 0 --clearmodifiers 2

# %%hotkey: paste primary selection using keyboard %%
shift + insert
    xdotool click --delay 0 --clearmodifiers 2
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay