How to copy but not to reset the screen?

44 views
Skip to first unread message

Peng Yu

unread,
Sep 1, 2020, 10:01:39 PM9/1/20
to tmux-users
I have the following ~/.tmux.conf. When I copy text I select the text, the text got automatically copied (in Mac Terminal). But the screen got reset too. I don't want this behavior. I want to select the text then type command-C to copy the text without resetting the screen. Is there way to get this behavior in the configuration? Thanks.

# Send prefix
set-option -g prefix C-a
set-option -g repeat-time 2000
bind-key c-R source-file ~/.tmux.conf \; display-message "~/.tmux.conf sourced"

bind-key v split-window -h -c "#{pane_current_path}" #\; switch-client -T prefix
bind-key s split-window -v -c "#{pane_current_path}" #\; switch-client -T prefix

bind-key -r h select-pane -L
bind-key -r j select-pane -D
bind-key -r k select-pane -U
bind-key -r l select-pane -R

bind-key -r - resize-pane -D
bind-key -r + resize-pane -U
bind-key -r < resize-pane -L
bind-key -r > resize-pane -R

bind-key c new-window -c "#{pane_current_path}"

bind-key -r n next-window
bind-key -r p previous-window

#bind-key -T root C-'[' next-window
#bind-key -T root C-']' previous-window

set-option -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
#bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

bind-key -T prefix P paste-buffer

set-option -g history-limit 10000
set-option -g mouse on

# https://github.com/tmux/tmux/issues/1113
#bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
#bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "cat >/tmp/foo"
bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel pbcopy

Nicholas Marriott

unread,
Sep 2, 2020, 1:41:35 AM9/2/20
to Peng Yu, tmux-users
What do you mean the screen gets reset?

--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/90509f4f-41ea-4396-928d-7536e4adbf19n%40googlegroups.com.

Suraj N. Kurapati

unread,
Sep 2, 2020, 1:46:35 AM9/2/20
to tmux-...@googlegroups.com, Nicholas Marriott, Peng Yu, tmux-users
I think he's referring to exiting copy mode. He wants to copy a selection using a shortcut and still remain in copy mode afterwards.

Stéphane GLEIZES

unread,
Sep 2, 2020, 8:00:07 AM9/2/20
to Suraj N. Kurapati, tmux-...@googlegroups.com, Nicholas Marriott, Peng Yu
I think you can use 'copy-pipe' instead of 'copy-pipe-and-cancel' for that purpose.

Stéphane Gleizes
LinkedIn

Peng Yu

unread,
Sep 2, 2020, 3:28:07 PM9/2/20
to Stéphane GLEIZES, Suraj N. Kurapati, tmux-...@googlegroups.com, Nicholas Marriott
I changed copy-pipe-and-cancel to copy-pipe. But the cursor still is
reset to the bottom of the history. I want the cursor to remain at its
original position (it could be several pages back.). Thanks.

On 9/2/20, Stéphane GLEIZES <stephane...@gmail.com> wrote:
> I think you can use 'copy-pipe' instead of 'copy-pipe-and-cancel' for that
> purpose.
>
> Stéphane Gleizes
>
>> > > (mailto:tmux-users+...@googlegroups.com).
>> > > (https://groups.google.com/d/msgid/tmux-users/90509f4f-41ea-4396-928d-7536e4adbf19n%40googlegroups.com?utm_medium=email&utm_source=footer).
>> >
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "tmux-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to tmux-users+...@googlegroups.com
>> (mailto:tmux-users+...@googlegroups.com).
>> To view this discussion on the web, visit
>> https://groups.google.com/d/msgid/tmux-users/F8D4BDA8-8217-416D-B885-43BE05DB0554%40riseup.net
>> (https://groups.google.com/d/msgid/tmux-users/F8D4BDA8-8217-416D-B885-43BE05DB0554%40riseup.net?utm_medium=email&utm_source=footer).
>>
>
>


--
Regards,
Peng

Stéphane GLEIZES

unread,
Sep 3, 2020, 6:42:17 AM9/3/20
to Peng Yu, Suraj N. Kurapati, tmux-...@googlegroups.com, Nicholas Marriott
Strange, that's not expected behavior.

I have the following binding and it works like a charm (tmux 3.2):
# Copy the current selection to a new buffer or start one if none is active.
bind -T copy-mode 'Space' {
  if -F '#{||:#{selection_active},#{search_present}}' {
    send -X copy-pipe
  } {
    send -X begin-selection
  }
}

If you are referring to mouse support, this is what I'm using:
# Avoid cancelling copy-mode if the pane history has been scrolled.
bind -T copy-mode 'MouseDragEnd1Pane' {
  if -F "#{scroll_position}" {
    send -X copy-pipe
  } {
    send -X copy-pipe-and-cancel
  }
}

Peng Yu

unread,
Sep 3, 2020, 11:49:49 AM9/3/20
to Stéphane GLEIZES, Suraj N. Kurapati, tmux-...@googlegroups.com, Nicholas Marriott
I used these lines. But they don't help.

When I type ctrl-a [ then ctrl-b, then use my mouse to highlight a
text region, the cursor will still be reset to the very bottom.

I use tmux 3.1b.

Could you try my configure file to see what is wrong? Thanks.

> Strange, that's not expected behavior.
>
> I have the following binding and it works like a charm (tmux 3.2):
> # Copy the current selection to a new buffer or start one if none is
> active.
> bind -T copy-mode 'Space' {
> if -F '#{||:#{selection_active},#{search_present}}' {
> send -X copy-pipe
> } {
> send -X begin-selection
> }
> }
> If you are referring to mouse support, this is what I'm using:
> # Avoid cancelling copy-mode if the pane history has been scrolled.
> bind -T copy-mode 'MouseDragEnd1Pane' {
> if -F "#{scroll_position}" {
> send -X copy-pipe
> } {
> send -X copy-pipe-and-cancel
> }
> }

--
Regards,
Peng

Stéphane GLEIZES

unread,
Sep 3, 2020, 1:18:43 PM9/3/20
to Peng Yu, Suraj N. Kurapati, tmux-...@googlegroups.com, Nicholas Marriott
I just tried with your configuration, replacing both occurrences of copy-pipe-and-cancel by copy-pipe and it works with the exact use case that you described (mouse selection). I'm using 3.2 though.

Things you can check:
  • Make sure that you replaced the MouseDragEnd1Pane binding to copy-pipe.
  • Make sure that you reload the tmux configuration. If in doubt, exit tmux and run `tmux kill-server`,  then start a new session.

If that still does work, maybe try upgrading tmux to 3.2 but I doubt that this is the root cause.

Stéphane Gleizes
LinkedIn

topcat

unread,
Sep 5, 2020, 11:13:30 PM9/5/20
to tmux-users
For me using copy-pipe works for tmux 2.9a which is the oldest I have.

Peng Yu

unread,
Sep 6, 2020, 7:03:46 PM9/6/20
to topcat, tmux-users
I have the following lines in my ~/.tmux.conf. When I use mouse to
copy the text, the cursor will not be reset to the bottom. But when I
use y to copy the highlighted text, the cursor will be reset to the
bottom. Why they don't have the same behavior?

bind-key -T copy-mode-vi y send-keys -X copy-pipe pbcopy
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe pbcopy

In your test, you don't have the cursor reset to the bottom in either
cases? Thanks.

On 9/5/20, topcat <anin...@gmail.com> wrote:
> For me using copy-pipe works for tmux 2.9a which is the oldest I have.
>
> On Thursday, September 3, 2020 at 10:18:43 AM UTC-7 stephane...@gmail.com
> wrote:
>
>> I just tried with your configuration, replacing both occurrences of
>> copy-pipe-and-cancel by copy-pipe and it works with the exact use case
>> that
>> you described (mouse selection). I'm using 3.2 though.
>>
>> Things you can check:
>>
>> - Make sure that you replaced the MouseDragEnd1Pane binding to
>> copy-pipe.
>> - Make sure that you reload the tmux configuration. If in doubt, exit
>> tmux and run `tmux kill-server`, then start a new session.
>>
>>
>> If that still does work, maybe try upgrading tmux to 3.2 but I doubt that
>>
>> this is the root cause.
>>
>> *Stéphane Gleizes*
>> [image: LinkedIn]
>> <https://www.linkedin.com/in/stephane-gleizes-4924b899/>
>> On Sep 3 2020, at 5:49 pm, Peng Yu <peng...@gmail.com> wrote:
>>
>> I used these lines. But they don't help.
>>
>> When I type ctrl-a [ then ctrl-b, then use my mouse to highlight a
>> text region, the cursor will still be reset to the very bottom.
>>
>> I use tmux 3.1b.
>>
>> Could you try my configure file to see what is wrong? Thanks.
>>
>> Strange, that's not expected behavior.
>>
>> I have the following binding and it works like a charm (tmux 3.2):
>> # Copy the current selection to a new buffer or start one if none is
>> active.
>> bind -T copy-mode 'Space' {
>> if -F '#{||:#{selection_active},#{search_present}}' {
>> send -X copy-pipe
>> } {
>> send -X begin-selection
>> }
>> }
>> If you are referring to mouse support, this is what I'm using:
>> # Avoid cancelling copy-mode if the pane history has been scrolled.
>> bind -T copy-mode 'MouseDragEnd1Pane' {
>> if -F "#{scroll_position}" {
>> send -X copy-pipe
>> } {
>> send -X copy-pipe-and-cancel
>> }
>> }
>>
>>
>> --
>> Regards,
>> Peng
>>
>>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "tmux-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/tmux-users/0ffonwnQjEs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> tmux-users+...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/tmux-users/5b0906cb-3cb8-4fd5-9d52-8d8e6275128an%40googlegroups.com.
>


--
Regards,
Peng

topcat

unread,
Sep 6, 2020, 9:44:37 PM9/6/20
to tmux-users
Hi, I tried your bindings and no, the cursor does not exit copy mode. I'm on a mac as well and both the tmux copy buffer and the macOS clipboard receive the text (through pbcopy). The cursor stays at its last position (when y was pressed) in copy-mode(-vi).

Do you get the reset behaviour for a completely empty .tmux.conf with only those two lines?
Reply all
Reply to author
Forward
0 new messages