Use the following tmux.conf
with copy-pipe
in the new versions of tmux (1.8+):
set -g mouse on
# To copy:
bind-key -n -t emacs-copy M-w copy-pipe "xclip -i -sel p -f | xclip -i -sel c "
# To paste:
bind-key -n C-y run "xclip -o | tmux load-buffer - ; tmux paste-buffer"
prefix+[
into copy-mode
- select content with mouse(hold)
M-w
to copy that part into system clipboard
C-y
the paste it inside tmux, C-v
to paste it inside other regular application like web browser.
As it turns out, the link in the question hinted at a working solution in the form of xclip
:
pandoc -S file.mkd | xclip -t text/html
...and then I can paste it straight into the document in libreoffice, properly formatted. This works with the versions of the programs in the Ubuntu 13.04 repositories (pandoc 1.10.1 and xclip 0.12) -- the -t
option for xclip especially is only in version 0.12 or above. The -S
option of pandoc makes it produce 'typographically correct output', so --
is turned into an en-dash, ---
is turned into an em-dash, and a few other things.
If you want to use the ctrl-v
clipboard, use:
pandoc -S file.mkd | xclip -t text/html -selection clipboard
Edit: if you're running OS X (with pbcopy
rather than xclip
), use:
pandoc -S file.mkd | textutil -stdin -format html -convert rtf -stdout | pbcopy
To transform selected text without creating a file, you can use:
xclip -o | pandoc -S | xclip -t text/html
...this can, of course, be mapped to a keyboard shortcut.
This can work well with a number of text markup formats as input, see the pandoc guide for some more information on how to accomplish this (you might need to use the -f/--from/-r/--read
option, especially if you're using the xclip|pandoc|xclip
version).
As a side note, you can also read an already-existing HTML file into xclip
:
xclip -t text/html <file.html
or
<file.html xclip -t text/html
Best Answer
I have a couple of imperfect, but maybe useful, ideas.
Method 1 - mousey.
Use the terminal scrollbar.
Details (assuming
xterm
; adjustments will be required for other terminals.)xterm
, it's in the menu you get with Ctrl+Button2.)less
is not running with the-c
option (I have this option enabled in myLESS
environment variable, but it interferes with what we're about to do, so I have to type-c
to turn it off.)less
commands you like, scroll up or down so the first line you want to copy is visible on the screen./
search - the point here is to getless
to send all the lines to the terminal so they can be copied.Possible difficulty: your scrollback buffer may not be big enough. That can be changed in
xterm
with thesaveLines
resource or-sl
command line option, but I don't know of a way to change it in an xterm that's already running.Method 2 - non-mousey.
Use the
|
(pipe) command inless
to send the text toxclip
.Details:
less
commands you like, scroll up or down to position the last line you want to copy at the top of the screen. You can skip this step and the next step if you want to copy all the way to the end.m
(mark) command to set a mark at your chosen end position. Marks are a useful feature by themselves, and you should know them already fromvi
, but just in case you don't: mx sets a mark, where thex
can be any letter, and 'x returns you there later.x
should be the same mark letter you used in them
command, or$
for "all the way to the end". Typexclip
there.The simple case of copying the entire man page reduces to g|$xclipEnter.
Warning (i.e. the horrible thing that just happened to me):
xclip
will be semi-backgrounded, running as part of theless
process group. If you try to suspendless
, start another job on the same terminal, and paste into it, it will not work. Then when you later foreground theman
/less
job, suddenly the paste will come through. I think this should be considered anxclip
bug...