.tmux: Avoid auto jump after selection & search outputs

Created on 22 Nov 2017  路  12Comments  路  Source: gpakosz/.tmux

Very grateful for your nice configs of tmux, however I am facing two issues here:

  1. In mouse mode, when I select text for previous output text, then automatically jump to the bottom. Very annoying here, what should I do? How can I only enable Escape key for return to bottom?

  2. I want to search output results, how can I do that?

tmux support

Most helpful comment

Hello @changkun

  1. is tmux's default behavior:
$ tmux -f /dev/null
$ tmux list-keys | grep copy-selection
bind-key    -T copy-mode    C-w               send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode    MouseDragEnd1Pane send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode    M-w               send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode-vi C-j               send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode-vi Enter             send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection-and-cancel

I think you can edit your ~/.tmux.conf.local copy and redefine the default bindings to use copy-selection instead of copy-selection-and-cancel:

bind-key    -T copy-mode    C-w               send-keys -X copy-selection
bind-key    -T copy-mode    MouseDragEnd1Pane send-keys -X copy-selection
bind-key    -T copy-mode    M-w               send-keys -X copy-selection
bind-key    -T copy-mode-vi C-j               send-keys -X copy-selection
bind-key    -T copy-mode-vi Enter             send-keys -X copy-selection
bind-key    -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection
  1. I'm not sure I understand the question

All 12 comments

Hello @changkun

  1. is tmux's default behavior:
$ tmux -f /dev/null
$ tmux list-keys | grep copy-selection
bind-key    -T copy-mode    C-w               send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode    MouseDragEnd1Pane send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode    M-w               send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode-vi C-j               send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode-vi Enter             send-keys -X copy-selection-and-cancel
bind-key    -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection-and-cancel

I think you can edit your ~/.tmux.conf.local copy and redefine the default bindings to use copy-selection instead of copy-selection-and-cancel:

bind-key    -T copy-mode    C-w               send-keys -X copy-selection
bind-key    -T copy-mode    MouseDragEnd1Pane send-keys -X copy-selection
bind-key    -T copy-mode    M-w               send-keys -X copy-selection
bind-key    -T copy-mode-vi C-j               send-keys -X copy-selection
bind-key    -T copy-mode-vi Enter             send-keys -X copy-selection
bind-key    -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection
  1. I'm not sure I understand the question

Hi @gpakosz , thanks for you quickly response. Question 1 works for me 馃憤

Maybe I need to rephrase my second question.

What I mean here is, for a tmux window, when I enable mouse mode, I am able to scroll up for retrieve the console output history. for example, in vim, I can type / at command mode with text for searching. Thus, how can I search the historical text in this tmux configuration?

@changkun My configuration doesn't change search bindings. Enter copy mode by either scrolling up when mouse mode is on or by hitting <prefix> + Enter and when you're in copy mode use the / key just like in vim.

Hope that helps

@gpakosz ..Here is the point, I tried them before I create this issue, <prefix>+Enter does get in to copy mode, but after that / and any other key doesn't works

I don't know what you did to your configuration then...

$ tmux list-keys | grep 'search down'
bind-key    -T copy-mode    C-s               command-prompt -i -I "#{pane_search_string}" -p "(search down)" "send -X search-forward-incremental \"%%%\""
bind-key    -T copy-mode-vi /                 command-prompt -p "(search down)" "send -X search-forward \"%%%\""

Please make sure you whatever you suspect doesn't work with this configuration works with stock tmux settings. You can do so by launching tmux -f /dev/null which skips loading ~/.tmux.conf

Oh right I think I get it. If you want vi like behavior you have to export EDITOR=vim from e.g. your ~/.bashrc or ~/.bash_profile.

From tmux manual:

status-keys [vi | emacs]
        Use vi or emacs-style key bindings in the status line, for example at the command prompt.  The default is emacs, unless the VISUAL or
        EDITOR environment variables are set and contain the string `vi'.

And I also mention it in README.md

If you're a Vim user, setting the $EDITOR environment variable to vim will enable and further customize the vi-style key bindings (see tmux manual).

@gpakosz sadly doesn't work.. I have enabled $EDITOR as you mentioned in README...

is it because I use mvim as alias for vim?

qq20171122-181022

Did you relaunch tmux after having exported $EDITOR?

You should see:

$ tmux show -wg mode-keys
mode-keys vi
$ tmux show -g status-keys
status-keys vi

If for some reason exporting $EDITOR doesn't work for you (while it really should), you can uncomment the lines in your ~/.tmux.conf.local copy:

# force Vi mode
#   really you should export VISUAL or EDITOR environment variable, see manual
#set -g status-keys vi
#set -g mode-keys vi

@gpakosz Thank you so much! I never tried relaunch tmux, only <prefix-r> for reload... now finally works 馃憤 Really appreciate your help

You're welcome. Spread the tmux 鉂わ笍

@gpakosz always recommend your nice configuration to my friends 鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fwarmuth picture fwarmuth  路  5Comments

billowqiu picture billowqiu  路  8Comments

mattysweeps picture mattysweeps  路  6Comments

bubble-joe picture bubble-joe  路  4Comments

MadaraUchiha picture MadaraUchiha  路  6Comments