I have installed tmux.
tmux -V
tmux 2.3
Set my configure file.
cat ~/.tmux.conf
set -g mouse on
Enter tmux and open a two vertical windows in it,open python3 console in the left,open vim in the right.
Now move my cursor at the beginning of the first line in the right with mouse.
Enter into normal mode and input 2yy+
, to copy two lines in my +
register.
Move cursor at the left python3 console
window ,how can i paste content in +
register into the python console?
@Kent,do as you say:
1.Move cursor at the beginning of first line,and type "+2Y
2.Move cursor to the left window,and middle-click mouse,nothing happen.
3.press ctrl+b
then press ]
key.
first your vim should be compiled with +clipboard
see vim --version | grep 'clipboard'
To copy ( or delete ) in any vim register you can use the following syntex
"<register name><oprator><motion>
(see :h registers
)e.g.
"ayy
(copy current line in register a
) or "bdd
(delete current line in register b
) or"*ce
(delete to the end of the current work and place content in register *
using c
will also put you in insert modeyy
+
or *
( depending on the os )so to copy the whole line into system clipboard you can use
"*yy
or "+yy
(depending on the os)or to copy 2 lines
"*2yy
or "+2yy
( to copy current and the line after current line )once the content is copied in the system clipboard you can paste in tmux using ( command + v
or ctrl + shift + v
)
or to map system clipboard with tmux paste buffer see https://unix.stackexchange.com/questions/67673/copy-paste-text-selections-between-tmux-and-the-clipboard#72340
2yy+
does NOT copy two lines into +
reg, instead, it yanks two lines to "
reg, then moves the cursor to first non-blank char in next line
You can on the vim side do: "*2Y
then do a mouse middle-click on the python console.
I didn't quite like with the accepted solution that it depends on a graphical environment for the clipboard since this does not work when vim
can not access the clipboard, which is almost always the case for ssh
connections.
So I cam up with another solution:
Instead of using the external clipboard vim
can pass the text directly into tmux
' paste buffer by piping it into
tmux load-buffer -
After that you can paste the content of the buffer with prefix + ]
into the active tmux
pane.
There are various ways to pass the text from vim
to tmux
:
# to write the current line into the tmux buffer:
:.w !tmux load-buffer -
# to write all *lines* within the visual selection into the tmux buffer:
:'<,'>w !tmux load-buffer -
# to pipe the content of a register (e.g. from a previous selection) into the buffer:
# @" being the unnamed register, @0 - @9 the numbered registers, and so on
:call system('tmux load-buffer -', @")
Using tmux paste-buffer
you can even trigger the pasting into the correct pane at the same time:
# assuming the python pane is at :0.0
:call system('tmux load-buffer -; tmux paste-buffer -t :0.0', @")
You can now also easily map the last line to a key to send the visually selected text to the python
pane.
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