Can't bind \ key (unknown key: split-window error) - tmux

I'm usint tmux 3.3a on a mac and I'm trying to bind the \ in my tmux.conf file
bind-key \ split-window -h -c '#{pane_current_path}'
The problem is that \ seems to escape the next character and I get the following error:
/Users/myname/.tmux.conf:18: unknown key: split-window
I tried escaping the \ character
bind-key \\ split-window -h -c '#{pane_current_path}'
I also tried wrapping it into single quotes
bind-key '\' split-window -h -c '#{pane_current_path}'
But I still get the same error message
What should I do to solve this?

Related

tmux : copy and paste without shift

i'm trying to follow a guide in which it's explained how to get copy/paste working without shift.
but with the following config :
set -g mouse on
set -g #plugin 'tmux-plugins/tpm'
set -g #plugin 'tmux-plugins/tmux-yank'
set -g #yank_action 'copy-pipe-no-clear'
set -g #override_copy_command 'xsel -i --clipboard'
set -g #yank_selection_mouse 'primary'
set -g #yank_selection 'primary'
bind -T copy-mode C-c send -X copy-pipe-no-clear "xsel -i --clipboard"
bind -T copy-mode-vi C-c send -X copy-pipe-no-clear "xsel -i --clipboard"
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
I'm expecting to select something with the mouse, press y or Control-c, then go to any other app, press Control-v and have my selection pasted, but nothing happens.
when I list the keys I can see my bind:
bind-key -T copy-mode C-c send-keys -X copy-pipe-no-clear "xsel -i --clipboard"
and xsel works fine on its own :
$ echo hello | xsel -i --clipboard # C-V contains 'hello' as expected
What am i doing wrong?

Inconsistent window behavior on tmux startup

I'm using iTerm2's hotkey window to open a default set of tmux panes whenever I first launch the window. I have a file named .hotkeyconfig I'm using to source the commands necessary to size the window.
tmux new -s hotkey \; \
select-pane -t 0 \; \
split-window -h \; \
resize-pane -t 0 -L 34 \; \
split-window -h \; \
resize-pane -L 15 \; \
split-window -h \; \
resize-pane -R 19 \; \
select-pane -t 1 \; \
split-window -v \; \
resize-pane -U 2 \; \
resize-pane -R 10 \; \
select-pane -t 0 \; \
I call this when the window starts with:
source ~/.hotkeyconfig
When there's another attached tmux session using this command produces the top result, however if the hotkey window is the only attached tmux session, it produces the output on the bottom.
output
What is causing this inconsistent behavior and how can I fix it?

Tmux bind-key not working for split-window

I have following configuration in my tmux config file:
unbind C-b
set -g prefix C-s
bind-key - split-window -v
bind-key \ split-window -h
When I am in tmux, if I try
Ctrl+s : split-window -v
it works. If I try
Ctrl+s -
it does not work. It says No Buffer, and tmux does not do anything.
Any help on how can I debug this behaviour?
The - key is already bound to the delete-buffer command. You can check this by executing tmux list-keys. You must unbind it and then apply your binding:
unbind -
bind-key - split-window -v

Iterm2 with tmux intergration not using keybindings from .tmux.conf

I have been using tmux in iTerm2 for a while now but I have not been using the tmux integration that now comes with iTerm2.
I started looking at using the tmux intergration as it allows you to use the shell intergration inside tmux.
The problem i am encountering is that after i do tmux -CC none of the key bindings inside my .tmux.conf work... I cant even get any of the defaults to work. I would really like to use tmux integration but cant unless i can get the key bindings in my .tmux.conf to work.
Some of the bindings that are not working are;
Rebound the prefix key to C-s
bind-key \ split-window -v -c '#{pane_current_path}'
bind-key - split-window -h -c '#{pane_current_path}'
These are just a couple of examples but basically nothing seems to be working...
My .tmux.conf is
# improve colors
set-option -g default-terminal "screen-256color"
# set base Prefix key to ctrl-s
unbind C-b
set -g prefix C-s
bind-key -r C-s send-prefix
# reload the source config
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
set-option -g status-keys "emacs"
#change colour of status bar
set-option -g status-bg '#666666'
set-option -g status-fg '#aaaaaa'
# set window split
bind-key - split-window -v -c '#{pane_current_path}'
bind-key \ split-window -h -c '#{pane_current_path}'
# set text in status bar
set -g status-interval 1
set -g status-justify centre # center align window list
set -g status-left-length 50
set -g status-right-length 140
set -g status-left '#[fg=green]#H #[fg=black]• #[fg=green,bright]#(uname -r | cut -c 1-6)#[default]'
set -g status-right '#[fg=green,bg=default,bright]#(tmux-mem-cpu-load -i 1) #[fg=red,dim,bg=default]#(battery -at) #[fg=white,bg=default]%a%l:%M:%S %p#[default] #[fg=blue]%Y-%m-%d'
# Fine adjustment (1 or 2 cursor cells per bump)
bind -n S-Left resize-pane -L 2
bind -n S-Right resize-pane -R 2
bind -n S-Down resize-pane -D 1
bind -n S-Up resize-pane -U 1
# new window opens in same directory
bind c new-window -c "#{pane_current_path}"
# set window numbering to start from 1
set -g base-index 1
set -g renumber-windows on
# allow to take a pane and put it into new window
bind-key b break-pane -d
# allows ctrl-j to open tree of tmux sessions
bind-key C-j choose-tree
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Setup 'v' to begin selection as in Vim
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
# Update default binding of `Enter` to also use copy-pipe
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"
# History
set -g history-limit 10000
# Mouse mode
set-option -g mouse on
# Rename Tab
set-option -g set-titles on
# Terminal notifier doesnt work with tmux
set -g default-command "which reattach-to-user-namespace > /dev/null && reattach-to-user-namespace -l $SHELL || $SHELL -l"
set-option -sg escape-time 10
Copying my answer at https://stackoverflow.com/a/47171067/4200039 over:
Someone reported a similar bug at iTerm2 Tmux Integration Default Keybindings not working in 2015. The response from the developer George Nachman suggests that keybindings are not supported:
One of the main goals of the tmux integration is that you use iTerm2's
keystrokes, not tmux's. If there's a specific workflow that you can't
accomplish natively, let me know--there is a lot of power in the
ability to remap keys in iTerm2.
This should be flagged as a duplicate of iTerm 2 not honoring key bindings declared in .tmux.conf but I can't flag it until it has an accepted or upvoted answer.

Can I use double click to select and copy in tmux?

I am learning to use tmux, I found when I in a tmux window, double-click to select and copy function did not work any more.
Can I use double-click to select and copy just as in iterm2?
I have googled for some time, but did not find an short and clear answer to this. I have added setw -g mode-mouse on in the tmux configure file already.
I found a way to achieve that: hold the option key when double clicking.
Don't know about iterm2, but this can be made to work in tmux 3.0 or newer(tested on Linux w/ tmux 3.0, last command uses X11 xclip).
Added triple click to select and copy a line too.
# Double LMB Select & Copy (Word)
bind-key -T copy-mode-vi DoubleClick1Pane \
select-pane \; \
send-keys -X select-word-no-clear \; \
send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
# Triple LMB Select & Copy (Line)
bind-key -T copy-mode-vi TripleClick1Pane \
select-pane \; \
send-keys -X select-line \; \
send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
bind-key -n TripleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-line \; \
send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
If you don't use copy-mode-vi, replace this with copy-mode.
For older tmux versions check the edit-history.
In Alacrity holding Shift allows copying as if there's no tmux.
source
Building off of #ideasman42 's answer. This is using tmux 2.8 and pbcopy for macos mojave.
# Double LMB Select & Copy (Word)
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
run-shell "sleep .5s" \; \
send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
run-shell "sleep .5s" \;
send-keys -X copy-pipe-and-cancel "pbcopy
My version selects the word, briefly highlights it, copies it to the system buffer and then cancels copy-mode.
I have figured out a copy paste mechanism that is similar of what you will expect form a terminal
I used the following settings to be able to:
select a word with a mouse double click action
select a line with a mouse tripple click action
select a partial line a mouse drag and drop action
This solution will keep the selection highlighted and copy the selection output to both clipboard buffers (primary and clipboard)
When you hit "Enter" you exit and go back to the shell
The advantage here is that you can use both middle mouse button as shift-insert combination outside of tmux to paste the content, while it is still selected.
Also when you exited back to the shell, you can use middle mouse button or hit shift-insert to paste the content
All what you would expect from a normal terminal environment
# Enable mouse control
setw -g mouse on
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter \
send -X cancel
# Drag and Drop Aelect & Copy (Selection)
bind-key -T copy-mode-vi MouseDragEnd1Pane \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
# Double LMB Select & Copy (Word)
bind-key -T copy-mode-vi DoubleClick1Pane \
select-pane \; \
send-keys -X select-word \; \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
bind-key -n DoubleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-word \; \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
# Triple LMB Select & Copy (Line)
bind-key -T copy-mode-vi TripleClick1Pane \
select-pane \; \
send-keys -X select-line \; \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
bind-key -n TripleClick1Pane \
select-pane \; \
copy-mode -M \; \
send-keys -X select-line \; \
send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
send-keys -X no-clear
# Middle click to paste from the primary buffer
unbind-key MouseDown2Pane
bind-key -n MouseDown2Pane run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
# Shift insert to paste from the clipboard
unbind-key S-IC
bind-key S-IC run "tmux set-buffer \"$(xclip -o -sel c)\"; tmux paste-buffer"
NOTE1 : in order for this to work across a ssh session : -X has to be provided as option to ssh
NOTE2: I'm using tmux version 2.8
On Kitty/Alacritty, we double-click on the text-block while keeping Shift pressed. And copying works fine natively as well as within tmux.
Just uncheck the "Enable mouse reporting" option in iTerm2.
But this has side effect: set -g mouse on in ~/.tmux.conf will not work.

Resources