I have no luck binding square brackets in tmux with the following config:
bind-key ] select-window -t :=6
bind-key [ select-window -t :=7
I have tried escaping brackets like "\[", but it didn't help. Any suggestions here?
There is nothing wrong with tmux. The problem was in my config, where brackets were binded, then unbinded a few lines later.
Related
I want to bind this to something more convenient, like M-] without the prefix:
bind -n M-] send-prefix \; send-keys )
in my tmux.conf doesn't work.
What's my mistake?... I also tried C-] and some others. When I'm at a prompt, it just writes the ) character, so the prefix isn't being captured by tmux.
There doesn't seem to be a command for "next session", just the predefined binding.
I put these lines in my .tmux.conf:
bind j switch-client -n
bind k switch-client -p
As you can see the -n and -p arguments are next and previous. Enjoy!
This is my .tmux.conf file, placed in the home directory.
unbind C-b
set -g prefix S-a
bind S-a send-prefix
bind r source-file ~/.tmux.conf
I am properly loading it with tmux source-file ~/.tmux.conf. However, doing shift+a to initiate the prefix doesn't work.
However if I replace S-a with C-a, it'll work (ctrl+a).
What am I doing wrong?
You can't and it's not a good idea, the shift key is by no way meant for that. Take a look in the man tmux, section KEY BINDINGS for the list of available keys. More info are available here https://unix.stackexchange.com/a/140010
Solution 1
Run: (WARN: Save your work in all sessions first)
tmux kill-server
Solution 2
In your .zshrc/.bashrc file, add the following line:
[ -z "${TMUX}" ] || tmux YOUR_COMMAND
e.g. YOUR_COMMAND = set -g prefix S-a.
Is there any way to split a window in tmux without changing the current focus?
I'm running a script inside one of my tmux panes that occasionally runs "tmux split-window ..." with some command that takes a minute to complete and MAY request input.
I can end up trying to type input into one of the tmux panes but in the middle of my typing, the original pane executes "tmux split-window ..." and (mid word) my cursor shifts to the new pane, and I end up typing part of the input into the wrong pane.
Note: this answer is correct, but obsolete. The right way is to use -d flag for split-window command. I'm leaving this answer as a demonstration how to do some yak shaving with tmux.
A split-window command flag provided by tmux would be the right solution for this. Unfortunately tmux does not provide such command flag. Update: there is a -d split-window flag that does this.
The simple solution is to immediately switch to previous pane after split-window:
tmux split-window
tmux last-pane
This can be also written as a one liner:
tmux split-window\; last-pane
The downside of this solution is that *theoretically* you might end up writing a character in the wrong window if you type it in time interval between split-window and last-pane command execution.
Here another approach with the downside that it's more complex.
Create a new window in the background and get the pane_id of this window (note how this command is wrapped in $(...) because we want it executed in a subprocess:
pane_id=$(tmux new-window -d -P -F "#{pane_id}")
Now join the window we just created with the window where your cursor is located (will not change cursor focus):
tmux join-pane -b -t "$pane_id"
Add -h to the join-pane above if you want a horizontal split.
I recommend taking the first approach for it's simplicity. It's highly unlikely you'll have any practical issues with it.
I was wondering what the possible options are for tmux vi-copy bindings. I have the following in my .tmux.conf:
bind -t vi-copy e start-of-line
bind -t vi-copy r end-of-line
bind -t vi-copy v begin-selection
bind -t vi-copy V rectangle-toggle
bind -t vi-copy K page-up
bind -t vi-copy J page-down
bind -t vi-copy h cursor-left
bind -t vi-copy j cursor-down
bind -t vi-copy k cursor-up
bind -t vi-copy l cursor-right
bind -t vi-copy C-f cancel
Q1: I've had this in my config file for a while and have no idea where the options in the last column come from. A google search only showed me other forums that have code snippets like this. I can't find the documentation on these keywords. Any ideas? nope, not the manpage :)
Q2: If possible I would like to change K to (the tried and failed) half-page-up, or even to something like "go up 5 lines", to preserve context.
Tried and failed:
1) bind -t vi-copy K half-page-up
2) bind -t vi-copy K M-Up
3) bind -t vi-copy K C-u // already configured half page-up
Thx!
You can use tmux list-keys -t vi-copy to see a list of all the functions that are mapped in vi-copy mode. If you wish to see all possible commands you can look at the source code, specifically mode-key.c. I don't think there are any docs that list them all.
The mappings you are looking for are:
bind-key -t vi-copy 'K' halfpage-up
bind-key -t vi-copy 'J' halfpage-down
Unfortunately, this part is not documented well in tmux.
This is the full list of 'copy mode' commands in version 2.2 ripped out from the source code:
append-selection
back-to-indentation
begin-selection
bottom-line
cancel
clear-selection
copy-end-of-line
copy-line
copy-pipe
copy-selection
cursor-down
cursor-left
cursor-right
cursor-up
end-of-line
goto-line
halfpage-down
halfpage-up
history-bottom
history-top
jump-again
jump-backward
jump-forward
jump-reverse
jump-to-backward
jump-to-forward
middle-line
next-space
next-space-end
next-word
next-word-end
other-end
page-down
page-up
previous-space
previous-word
rectangle-toggle
scroll-down
scroll-up
search-again
search-backward
search-forward
search-reverse
select-line
start-named-buffer
start-number-prefix
start-of-line
top-line
All these commands apply to both vi-copy and emacs-copy modes but behavior might differ making it consistent with vi or emacs, though.
There are some shortcomings when tmux is 'in mode':
No sensible commands list or tab-completion for 'mode' commands
No way to combine commands in 'mode': you can only bind one action to a keypress and the set of actions is limited.
There's also a patch addressing these problems: http://ershov.github.io/tmux/
It adds full-fledged scripting support into tmux.
Using that, you can list all available commands:
info commands ::tmux::*
List all 'mode' commands:
info commands ::tmux::mode::*
List all 'copy mode' commands:
info commands ::tmux::mode::copy::*
Bind multiple actions in copy-mode:
bind-key -t vi-copy K tcl { scroll-up ; scroll-up }
Annoying question to have to ask! In bash (or anywhere.. like when editing this question) I can do CTRL + left|right to move left left or right to different bits of whitespace. With tmux running.. this does work.. it doesn't do anything. How do you do the same thing but with tmux?
Thank you.
You can do it by binding C-Left and C-Right to "send-keys M-b" and "send-keys M-f" in your ~/.tmux.conf file like this:
bind-key -n C-Left send-keys M-b
bind-key -n C-Right send-keys M-f
You don't. bash, respectively readline, has an idea of what you typed and can therefore jump as many characters until the next "word boundary". tmux does not have this information. Also, in tmux and the ANSI code space, I would interpret "end of line" in fact as \r\e[xB (with x being the size of the window), though that did not match up with your expectation.