I'm trying to become more proficient with tmux, but I ran into ( what seems to me ), a weird issue. Here's my tmux.conf:
1 TERM=screen-256color
2 set-option -g default-terminal $TERM
3
4 TMUX_COLOUR_BORDER="colour237"
5 TMUX_COLOUR_ACTIVE="colour231"
6 TMUX_COLOUR_INACTIVE="colour16"
7
8 set-window-option -g window-status-activity-bg $TMUX_COLOUR_BORDER
9 set-window-option -g window-status-activity-fg $TMUX_COLOUR_ACTIVE
10 set-window-option -g window-status-current-format "#[fg=$TMUX_COLOUR_ACTIVE]#I:#W#F"
11 set-window-option -g window-status-format "#[fg=$TMUX_COLOUR_INACTIVE]#I:#W#F"
12
13
14 set -g prefix C-a
15
16 bind-key o split-window -v
17 bind-key e split-window -h
18
19 bind-key w kill-pane
I'm trying to copy paste between two panes. So, I hit Ctrl-a-[ , and then Ctrl-space. The thing is, I don't see a visual selection of the block, and alt-w also does not work ( since I guess it's not even entering copy mode ). Is there an obvious error in my tmux.conf? Can you spot what I'm doing wrong?
tmux has an option, mode-keys, you can find it in man page.
default is emacs, but if your $EDITOR is vim/vi, tmux will use vi.
So the key binding will be in vi mode.
E.g. your Alt-w won't work, it is emacs binding. you can see a table of key-binds in tmux man page.
some related to your question:
Function vi emacs
Copy selection Enter M-w
Start selection Space C-Space
so you should go with the vi-mode keys.
I used vim mode too, and did a little customization (to make it same as vim) in my tmux.conf, maybe you could give it a try:
bind-key -t vi-copy 'v' begin-selection # Begin selection in copy mode.
bind-key -t vi-copy 'C-v' rectangle-toggle # Begin selection in copy mode.
bind-key -t vi-copy 'y' copy-selection # Yank selection in copy mode.
In case it helps, I had a correct tmux configuration (with vi like settings for selection & copy/paste) but needed to set these two environment variables in my .zshrc file (using Zsh & Neovim):
export EDITOR='nvim'
export VISUAL='nvim'
Related
Is there a way of displaying the currently running command (e.g. for situations where the script runs for days and you wish to retrieve the running parameters) as the tmux window name?
I.e
$ python train_net.py --lr 50 -> would cause the window name to change to python train_net.py --lr 50 instantly?
You can change tmux default config file. Usually it is in your home folder: ~/.tmux.conf. Add following lines to it:
set-option -g status-interval 1
set-option -g automatic-rename on
set-option -g automatic-rename-format '#{pane_current_command}'
You can change automatic-rename-format to any thing you like. pane_current_command means the current running command.
Then restart your tmux sessions or:
Ctrl+b then :source-file ~/.tmux.conf inside a tmux session to re read tmux config file.
Pay attention that this will automatically rename your tab if you haven't set a name for it manually, if you renamed it manually it won't make change.
For future references:
In ~/.tmux.conf add:
set-option -g status-interval 1
set-option -g automatic-rename on
set-option -g automatic-rename-format "#(ps -f --no-headers --ppid $(tmux display-message -p #{pane_pid}) | awk '{ print substr($0, index($0,$8)) }') "
set-option -g history-limit 3000
Then inside a tmux console ctrl+b :source-file ~/.tmux.conf to reload
Suddenly my tmux started with error .tmux.conf:41: usage: bind-key [-cnr] [-T key-table] key command [arguments]
on that line in tmux.conf was bind-key -t vi-copy v begin-selection
I suppose, the problem is with -t key, which is not predicted by bind-key command.
But it was working!
The different types of key table were integrated together and the -t flag dropped several years ago. Copy mode commands are now sent using send -X and the new table is called copy-mode-vi.
So your example becomes:
bind-key -Tcopy-mode-vi v send -X begin-selection
I just update to tmux 2.1(OS X10.11.3 Terminal.app), and my .tmux.conf(accroding to http://joehanchoi.com/quick-fixes-for-tmux-2-1-on-osx/)
set-option -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
but the problem is after I start tmux, the mouse pointer becomes a plus: +, and I cannot copy/paste anymore.
And right click on Terminal does not work, no popups
How to solve this?
There are two factors:
Terminal.app in El Capitan recognizes (some of) xterm's escape sequences for the mouse.
tmux 2.1 has some changes — for the (xterm) mouse protocol
This was discussed extensively in Mouse scrolling in tmux 2.1 on OSX no longer auto-starts #145 , but no one suggested a different configuration than the one you are using.
I am using tmux in a ssh session.
I am using multiple panes and windows.
I have mouse-mode enabled which works great so far.
When I select text it gets automatically copied to the tmux-buffer and the window jumps to the end.
So if i scroll up and click on something it jumps to the end...
When I switch between panes a copy command is triggered and the output goes to the end.
I really dislike this behaviour and I'd rather have to press a button to copy or click q to finish copy mode or something.
Is it possible to disable auto-copy // auto jump to the end on mouse button release?
I am running tmux 2.0 on the server through ssh. In Terminator on the client.
# config
#{{{
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
# set-window-option -g automatic-rename on
# set-option -g set-titles on
set -g default-terminal screen-256color
set -g history-limit 10000
set -g status-keys vi
setw -g mode-keys vi
setw -g mode-mouse on
set -g mouse-select-window on
set -g mouse-select-pane on
set -g mouse-resize-pane on
# No delay for escape key press
set -sg escape-time 0
#}}}
# bind keys
#{{{
# Reload tmux config
bind r source-file ~/.tmux.conf
# remap prefix to Control + a
set -g prefix C-a
# bind 'C-a C-a' to type 'C-a'
bind C-a send-prefix
unbind C-b
# switch tabs with <b n>
bind b previous-window
# vi like paste
bind-key p paste-buffer
# quick pane cycling
unbind a
bind a select-pane -t :.+
bind-key v split-window -h
bind-key s split-window -v
bind-key J resize-pane -D 10
bind-key K resize-pane -U 10
bind-key H resize-pane -L 10
bind-key L resize-pane -R 10
bind-key M-j resize-pane -D 2
bind-key M-k resize-pane -U 2
bind-key M-h resize-pane -L 2
bind-key M-l resize-pane -R 2
# Vim style pane selection
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind -n M-Down select-pane -D
# find asci keycodes with "sudo showkey -a" - works only tmux >1.7
# us-keyboard like [ ]
bind-key -r 0xc3 display 'c3 prefix binding hack'
bind-key -r 0xb6 copy-mode # ö
bind-key -r 0xa3 paste-buffer # ä
# us { }
bind-key -r 0x96 swap-pane -U # Ö - swap pane to prev position
bind-key -r 0x84 swap-pane -D # Ä - to next pos
#}}}
As of tmux 2.5 you should use
unbind -T copy-mode-vi MouseDragEnd1Pane
I'd say the easiest way nowadays is to just use the tmux-yank plugin and add the yank_action configuration option:
# ~/.tmux.conf
set -g #yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default
Additionally, tmux-yank also manages for you the differences between OS clipboards (Linux, macOS, WSL) and adds some very useful shortcuts for copying the current command line content and cwd. Highly recommended.
i was able to get mouse selection to stop jumping to the bottom in tmux (version 2.2) by adding the following to my ~/.tmux.conf:
setw -g mouse on
setw -g mode-keys vi
unbind -t vi-copy MouseDragEnd1Pane
caveat: this has the side effect of turning on vi mode.
i found this issue to be relevant, and found the configuration above in these dotfiles.
The following worked for me. Thanks to #stagebind on github!
For vi-mode config, https://github.com/tmux/tmux/issues/140#issuecomment-321144647:
unbind -T copy-mode-vi MouseDragEnd1Pane
For non vi-mode config, https://github.com/tmux/tmux/issues/140#issuecomment-302742783:
# 2.4+
unbind -T copy-mode MouseDragEnd1Pane
# 2.2 - 2.3
unbind -t vi-copy MouseDragEnd1Pane
Took me some time to get the correct answer.
I am also using Alacritty and cannot enable copy on mouse select because of an issue with MouseDragEnd1Pane as described in: https://github.com/jwilm/alacritty/issues/1002.
Selecting the text with the mouse and then if I need copy it using the key y works for me with this config:
bind -T copy-mode-vi y send -X copy-pipe "reattach-to-user-namespace pbcopy"\; display-message "copied to system clipboard"
Complete config for copy and pasting with mouse and vi key binding support looks like this:
set-option -g default-command "reattach-to-user-namespace -l bash"
set -g mouse on
bind P paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send -X copy-pipe "reattach-to-user-namespace pbcopy"\; display-message "copied to system clipboard"
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
## don't jump to bottom on mouse select - when vi-mode enabled - 2.4+
#unbind -T copy-mode MouseDragEnd1Pane
## don't jump to bottom on mouse select - when vi-mode enabled - 2.2 - 2.3
#unbind -t vi-copy MouseDragEnd1Pane
## don't jump to bottom on mouse select - when vi-mode enabled
unbind -T copy-mode-vi MouseDragEnd1Pane
I am using OS X.
as of tmux 2.2 the feature copy-selection -x is available. With the following options tmux stays in copy mode after selecting. Choose the one that fits your mode setting.
bind-key -t vi-copy MouseDragEnd1Pane copy-selection -x
bind-key -t emacs-copy MouseDragEnd1Pane copy-selection -x
Looks like upgrading to tmux 2.1 might solve your problem.
Reasonable mouse support in tmux
In version 2.1 they changed mouse-mode, mouse-select-window/pane etc with single mouse switch. Mouse actions now generates key events that can be mapped as ordinary keys.
I am running tmux (version 1.9a) on a Mac OS X 10.6.8 with iTerm 2.
My default shell is tcsh, and I have several alias (and path, environment variables) defined in my .tcshrc file.
The problem is that all the alias are not defined when I run tmux, although I set tmux to run with the tcsh shell by default.
Addition: On the other hand the environment variables set in my .tcshrc are correctly passed in tmux. It seems a problem related just to alias...
Below my .tmux.conf
# copy and paster
set-option -g default-command "reattach-to-user-namespace -l tcsh"
# Define the default shell
set-option -g default-shell /bin/tcsh
# Avoid problems with alias defined in .tcshrc
set-option -g default-command $SHELL
set-option -g default-command "source .tcshrc"
# look good
set -g default-terminal "screen-256color"
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# a mouse
set -g mode-mouse on
setw -g mouse-select-window on
setw -g mouse-select-pane on
# # Scroll History
set -g history-limit 30000
# Count sessions start at 1
set -g base-index 1
# act like vim
setw -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind-key -r C-h select-window -t :-
bind-key -r C-l select-window -t :+
unbind [
bind -t vi-copy v begin-selection
bind -t vi-copy y copy-selection
# after copying to a tmux buffer, hit y again to copy to clipboard
bind y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
bind N swap-window -t +1
bind P swap-window -t -1
# Reload .tmux.conf
#bind R source-file ~/.tmux.conf \; display-message " Config reloaded.."
# Hit [PREFIX]-R to reorder windows (i..e from 1-4-7-9 to 1-2-3-4 keeping the right order)
bind R \
set -g renumber-windows on\; \
new-window\; kill-window\; \
set -g renumber-windows off\; \
display-message "Windows reordered..."
# Rename your terminals
set -g set-titles on
set -g set-titles-string '#(whoami)::#h::#(curl ipecho.net/plain;echo)'
# Status bar customization
# Set status bar
set -g status-justify left
set -g status-bg black
set -g status-fg white
set-option -g status-interval 5
set -g status-right-length 150
set -g status-left ""
set -g status-right "#[fg=green] %m-%d-%Y %H:%M #(whoami)#minimul.com " # Add space so I can see Growl notifications in full-screen mode
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
setw -g aggressive-resize on
# Allows us to use '<prefix>-a' <command> to send commands to a TMUX session inside
# another TMUX session
bind-key a send-prefix
# Highlight active window
set-window-option -g window-status-current-bg red
Apparently the issue was solved by keeping the line
set-option -g default-command "reattach-to-user-namespace -l tcsh"
while erasing the lines
# Define the default shell
set-option -g default-shell /bin/tcsh
# Avoid problems with alias defined in .tcshrc
set-option -g default-command $SHELL
set-option -g default-command "source .tcshrc"
And restarting iTerm2 (no source or rehash did the job).
This would be because when you launch a standard shell from the terminal, it's a login shell, but with the option you've set for tmux, it's just an additional shell.
This line:
set-option -g default-command $SHELL
actually causes it to launch as a non-login shell. You've probably got some code blocked off with:
if($?loginsh) then
...
endif
which means that it doesn't get invoked in that case.
If you change the option to:
set-option -g default-command "$SHELL -l"
It will act like a login shell; alternatively remove the default-command, and in that case it will invoke the default shell as a login shell, which should have the same effect.
As an attempt at debugging this I started with a from-scratch .tcshrc containing:
echo tcshrc
if($?loginsh) then
echo login
endif
if($?prompt) then
echo prompt
endif
with set-option -g default-command "" (the default) I saw:
tcshrc
login
prompt
with set-option -g default-command "$SHELL" I see:
tcshrc
tcshrc
prompt
with set-option -g default-command "$SHELL -l" I see:
tcshrc
tcshrc
login
prompt
with set-option -g default-command "reattach-to-user-namespace tcsh" I see:
tcshrc
tcshrc
prompt
with set-option -g default-command "reattach-to-user-namespace -l tcsh" I see:
tcshrc
tcshrc
login
prompt