Tmux is excellent, but there is one quirk that is proving to be a pane. If I hit ctrl+b then go too fast to the arrow key in order to switch panes I end up just resizing the current pane. It would be very nice to get rid of that behaviour. Is this a problem solvable in tmux or is in some kind of lag in my OS?
tmux is fully configurable so, yes, it's possible to solve this issue.
I suggest that you take a look at the tmux man pages or at other resources like Pragmatic Bookshelf's "tmux 2" book.
As an example, you can fully remap the keys to use to split, move around and resize windows adding something like this to your ~/.tmux.conf file:
# Splitting panes
bind | split-window -h # Uses "|" to split pane horizontally
bind - split-window -v # Uses "-" to split pane vertically
# Remapping movement keys
bind h select-pane -L # Move focus to pane on the left
bind j select-pane -D # Move focus to pane above the current one
bind k select-pane -U # Move focus to pane below the current one
bind l select-pane -R # Move focus to pane on the right
bind -r C-h select-window -t :- # Move to previous window
bind -r C-l select-window -t :+ # Move to next window
# Resizing panes (notes that is using the uppercase here and resize by 5 chars)
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
Related
I know I can select a timux pane directly by prefix q. I modified this default binding to bind / display-panes \; select-pane -t : in my config.
What I want is to have the selection not by the numbers that overlay each pane after C /, but by letters, say homerow HJKL or some sort of combination thereof.
In my config, I have this:
#switch panels
bind k selectp -U # switch to panel Up
bind j selectp -D # switch to panel Down
bind h selectp -L # switch to panel Left
bind l selectp -R # switch to panel Right
so that I can prefix + h/j/k/l to switch panel.
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 am aware that I can manually bind individual keys in my .tmux.conf file, but according to this page I should be able to get vim-like key bindings in tmux simply by adding the following to my .tmux.conf, saving me having to maintain a list of keybindings:
set-window-option -g mode-keys vi
But this doesn't really seem to work as expected. Sure enough, when I press Ctrl+b [ I am able to navigate through my terminal history using vim keys hjkl, but when I press Ctrl+b k it doesn't take me to the above window, for that I still have to press Ctrl+b Up, same goes for down, left and right.
Why doesn't this work? Do I really have to map these keys manually on top of vi mode to get actual vi mode?
I'm using tmux 1.6
add this to your cnofig:
#switch panels
bind k selectp -U # switch to panel Up
bind j selectp -D # switch to panel Down
bind h selectp -L # switch to panel Left
bind l selectp -R # switch to panel Right
I've been a happy tmux user for a while now but there's one behaviour that's bugging me. When I switch panes using ^b-arrow, and then immediately press arrow-up (to get a command from history, for example), the window pane switches again. I understand this can be useful if you want to move through multiple panes quickly, but for me it's a pain in the backside since I keep ending up in panes I never meant to be in.
So, is there a way to set tmux so that the ^b-arrow command only switches pane once and ignores any following arrow key presses?
That happens because the default bindings for the arrow keys are setup with bind-key -r, specifying that they may be repeated. There are two ways that you can disable this.
First, you can use set-option repeat-time 0 to disable repeating entirely. This will affect all bindings. I find that to be very annoying when resizing panes.
Secondly, you can change the bindings for the arrow keys to use bind-key without the -r option:
bind-key Up select-pane -U
bind-key Down select-pane -D
bind-key Left select-pane -L
bind-key Right select-pane -R
If you spend a lot of times navigating panes, why not set up global mappings so you don't have to use prefixes at all, e.g. bind -n C-h select-pane -L to map ctrl-h to switching left, same as Vim.
See http://robots.thoughtbot.com/seamlessly-navigate-vim-and-tmux-splits for an even better solution that also navigates across Vim windows.
Another option is to make a binding to jump to the previous pane, if you are flicking back and forth between the same two panes.
bind-key C-a last-pane
If I'm working in a widescreen monitor I like to primarily use two panes and switch between them with C-a Ca.
If I'm working on a square monitor I'll use two windows. I'd like to be able to switch between them with C-a C-a as well without changing my tmux.conf.
If you always want C-a to
switch between panes when the active window has more than one pane, and
switch between windows when the active window has only one pane,
then you can use an if-shell that counts the number of panes in the active window to decide between last-pane and last-window:
bind-key C-a if-shell 'test $(tmux list-panes | wc -l) -gt 1' 'last-pane' 'last-window'
It will still be “up to you” to rearrange your panes when switching between “wide” and “square” configurations (e.g. via break-pane and join-pane).
In tmux 1.8 if-shell and run-shell do format expansion, so you can simply the shell command a bit:
bind-key C-a if-shell 'test #{window_panes} -gt 1' 'last-pane' 'last-window'
I'd like to suggest the following (adjust 80 to distinguish between your two terminal widths)
if-shell '[ "$COLUMNS" -gt 80 ]' 'bind-key C-a "select-window -t :.+"' 'bind-key C-a "next-window"'
but I'm either messing up the syntax, or COLUMNS isn't set in the relevant tmux environment, as the above shell expression always evaluates false for me.