Reputation: 742
I have two separate instances of Vim running. I would like to set up my system so that when I search for something
in one Vim (using /
, ?
, *
or #
), then press n
or N
in the other Vim, it searches for the same something
in the second Vim. I am running Ubuntu.
I already make use of the primary system clipboard for things yanked in vim by using set clipboard=unnamed
in my .vimrc file.
Research so far
The command-line tool "xsel" lets me access three different clipboards in Ubuntu: the primary clipboard (used when you select text and middle-click to paste), the clipboard clipboard (used for Ctrl+C, Ctrl+V etc.), and the secondary clipboard (which seems to be unused). My thought at the moment for Vim to use xsel to set the secondary clipboard when /
, ?
, *
or #
are used, and use xsel to access the same clipboard when n
or N
are pressed.
Upvotes: 4
Views: 557
Reputation: 329
I was going to just post the code I cobbled together for this here, but then decided to bundle it up into a tiny plugin: https://github.com/dahu/VimSharedSearch
Upvotes: 3
Reputation: 2320
With clipboard=unnamed
set, you can copy between the last-pattern register (the last thing you searched for), and the shared clipboard using let @/=@*
and let @*=@/
(*
is the clipboard, and /
is last-pattern).
So you can then create a function that copies the last-pattern into the clipboard and map to /
, ?
, *
or #
, and another which copies the clipboard to the last-pattern for n
or N
.
Upvotes: 1
Reputation: 49078
Not exactly what you were asking, but I use split windows (:sp
or :vsp
) for that purpose.
Upvotes: 0