d3vin
d3vin

Reputation: 399

How do I copy entire contents of file (>1 pane) in Tmux emacs copy mode?

i want to copy the entire contents of a file using emacs copy mode in tmux.

however when i enter copy mode, type C-space to start highlighting text, and then type M-> to jump to the end of the file, i end up just jumping to the file info section at the bottom of the tmux pane.

here's a pic showing what happens:

edit: i'm a new user and apparently can't post a pic yet. but basically you could imagine the yellow highlighted (selected) text in tmux copy mode. instead of the end of the file i can only highlight to the bottom of the pane (which looks kinda like this):

-u-:----F1 file_name.rb      Top L1      (Ruby)---------------------------------

my question is, how can i enter copy mode, start selecting text, and jump to the end of the file?

and if this isn't the best way to accomplish my goal (of copying an entire file's contents while in tmux), what's a better way of doing it?

thx!

p.s.

i've followed the instructions here: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard

and also the instructions from the pragmatic tmux book.

in case it helps, here're the relevant lines from my .tmux.conf file (which i mostly copied from the pragmatic tmux book):

# use pbcopy|pbpaste wrapper script
set-option -g default-command "reattach-to-user-namespace -l zsh"

# send contents of current tmux buffer to system clipboard
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"

# support pasting from the system clipboard
bind C-v run "tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste buffer"

# overriding "auto-detection" to always use emacs
set-option -g status-keys emacs
set-option -gw mode-keys emacs

Upvotes: 4

Views: 3132

Answers (2)

sbochins
sbochins

Reputation: 198

The answer is yes and it’s pretty easy:

You need to run one of the tmux commands. You can run a tmux command by doing Ctrl+b+: and typing the command.

load-buffer path

or

loadb path

for short

Upvotes: 3

Chris Johnsen
Chris Johnsen

Reputation: 224691

tmux does not really understand that you are running emacs in the tty that it has provided. It only knows what has been written to that tty; so, when you press M-> while in tmux copy-mode, it simply moves to the bottom of the pane’s scrollback history (M-> while in copy-mode runs the (copy-mode-specific) tmux command history-bottom).

You really need to approach this problem from inside emacs. Here are some (interactively runnable) example functions that you could bind to key in emacs:

(defun write-region-to-tmux-buffer (beg end)
  (interactive "r")
  (shell-command-on-region beg end "tmux load-buffer -" nil nil nil t))

(defun write-buffer-to-tmux-buffer ()
  (interactive)
  (write-region-to-tmux-buffer (point-min) (point-max)))

If you want to bypass the buffer and use the file instead (i.e. create a buffer from the file on the disk, not the (possibly modified) contents of the buffer), you might use something like this:

(defun write-buffer-file-to-tmux-buffer ()
  (interactive)
  (let ((fn (buffer-file-name)))
    (if fn
        (shell-command
         (concat "tmux load-buffer "
                 (shell-quote-argument fn)))
      (error "Not a file-backed buffer"))))

Upvotes: 1

Related Questions