how to search within shortcuts of tmux - tmux

Pressing ? within a tmux session lists out the available shortcuts.
But there are so many... how can one search for some text within those displayed shortcuts?

I figured it out. My tmux's default mode was in emacs. I just had to switch to Vi (which I am comfortable with). So all I had to do was:
set-window-option -g mode-keys vi

Related

Sequence of keypresses crashes tmux

When I type C-b : to get to the command prompt, hitting escape and then quickly hitting any (or most) other key will cause tmux to indefinitely pause on the status bar. If you press enter, you can get back to tmux, but if you pres any two alphanumeric keys will cause the tmux server to crash. I have tried this on both set -g status-keys vi and set -g status-keys emacs as well as set -o vi and set -o emacs in bash. None of them seem to have an effect. I got my coworker to replicate this on his machine, so it doesn't seem like it's only me. What's up?
Seems to be fixed in the very newly released (11 hours ago) tmux 3.3!

How do you switch from a tmux pane that you've scrolled up in to another tmux pane?

If I have two tmux panes open and I go to one and scroll back to the history using CTRL-B [, then for some reason I can't switch to the other pane without making the current pane scroll back to the bottom. Does anyone know how to work around this? Note that I use some custom tmux configuration, as described here, to make it easier to navigate between vim windows and tmux panes. Is this somehow messing up how tmux scrolling works?
Is it possible you're running into a conflicting default keybinding for tmux when it's in copy mode?
When tmux is running, you can check the currently active keybindings by doing prefix+?. When I do this on a bare tmux config, I can see that C-k is bound to send-keys -X copy-end-of-line, and it will move a buffer that's in copy mode to the end of the buffer, like you're describing. Alternatively, if you're using tmux's copy-mode-vi, then it looks like C-j is bound by default to send-keys -X copy-selection-and-cancel.
Try adding the following to your .tmux.conf:
unbind-key -Tcopy-mode C-k
unbind-key -Tcopy-mode-vi C-j
After this configuration update, I'm able to use C-j and C-k to navigate panes like described in the article you linked.

Tmux window or pane name won't change in GNOME Terminal

Using Fedora 25 and GNOME Terminal. I have used Tmux for a few years in Ubuntu with a long customized .tmux.conf file. Recently installed Tmux and Tmuxinator in Fedora.
When I open the Terminal. I see that the title is set to tom#localhost:~. When I create a new Tmux session such as tmux new -s panes. The title of the pane is still tom#localhost:~.
Inside the Tmux session. When I open a new window with name console like this new-window -n console. The title won't change to console and keeps saying tom#localhost:~.
I thought maybe tmux is not overriding the titles so I added this to the tmux.conf file:
set-option -g set-titles on
set -g terminal-overrides "xterm*:XT:smcup#:rmcup#"
That still doesn't do anything.
The Terminal settings. I have Profile/Command/When terminal commands set their own titles set to Replace initial title.
I cannot figure this out. What am I doing wrong here?
I am not exactly sure why it works. But this solves my problem.
Inside the .tmux.conf file I added the line set-option -g allow-rename off. At the top of the file I had the line set -g default -terminal "xterm". I removed this line.

How to force emacs-style status-keys in tmux?

I have this problem with tmux 1.8: I want to set status-keys option to 'emacs' because I really dislike entering commands in vi-mode. However adding the following line to .tmux.conf has no effect:
set -g status-keys emacs
When tmux is restarted, tmux show-options -g | grep keys says emacs but the actual behaviour is vi-style.
The root of the problem is the $EDITOR environment variable, which it set to vim in my case. The documentations states:
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'.
So apparently when the environment variable is "vim" it forces vi status-keys.
Is there a way to override this behaviour and have the prompt behave emacs-style despite the environment variable? I can obviously hack around this (like starting tmux with other env variables and restoring the original later) but I hope there is a clean solution.
Thanks!
I had this problem and I think I just figured it out. Are you by chance also using ZSH (Z Shell)?
I found this post that says that ZSH will also switch to "vi mode" if your VISUAL and/or EDITOR is set to vi/vim. So the problem I was having in tmux as actually bubbling up from ZSH!
In short, make sure you can use emacs-style keys in your shell outside of tmux. If you're using ZSH you can add bindkey -e to .zshrc to set emacs bindings. Then in .tmux.conf:
set -g mode-keys emacs
set -g status-keys emacs
Both status-key and mode-keys default to vi if EDITOR contains vi, but this is only a default (during startup, before the configuration files are processed). Setting either of these options in your configuration should override the EDITOR-based default.
Are you also setting mode-keys (which controls the key maps used in copy-mode, and the choose-… commands)?
set -gw mode-keys emacs

"tmux set -g mouse-mode on" not scrolling

To allow scrolling a tmux pane with a mouse, I put the following in my ~/.tmux.conf file:
set -g mouse-mode on
However, nothing changes. When I scroll, it still scrolls outside of tmux. Why is this?
So this option has been renamed in version 2.1 (18 October 2015)
From the changelog:
Mouse-mode has been rewritten. There's now no longer options for:
- mouse-resize-pane
- mouse-select-pane
- mouse-select-window
- mode-mouse
Instead there is just one option: 'mouse' which turns on mouse support
So this is what I'm using now in my .tmux.conf file
set -g mouse on
As #Graham42 noted, mouse option has changed in version 2.1. Scrolling now requires for you to enter copy mode first. To enable scrolling almost identical to how it was before 2.1 add following to your .tmux.conf.
set-option -g mouse on
# make scrolling with wheels work
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
This will enable scrolling on hover over a pane and you will be able to scroll that pane line by line.
Source: https://groups.google.com/d/msg/tmux-users/TRwPgEOVqho/Ck_oth_SDgAJ
Just a quick heads-up to anyone else who is losing their mind right now:
https://github.com/tmux/tmux/blob/310f0a960ca64fa3809545badc629c0c166c6cd2/CHANGES#L12
So that's just
:setw -g mouse
this should work:
setw -g mode-mouse on
then resource then config file
tmux source-file ~/.tmux.conf
or kill the server
Paste here in ~/.tmux.conf
set -g mouse on
and run on terminal
tmux source-file ~/.tmux.conf
As #Graham42 said, from version 2.1 mouse options has been renamed but you can use the mouse with any version of tmux adding this to your ~/.tmux.conf:
Bash shells:
is_pre_2_1="[[ $(tmux -V | cut -d' ' -f2) < 2.1 ]] && echo true || echo false"
if-shell "$is_pre_2_1" "setw -g mode-mouse on; set -g mouse-resize-pane on;\
set -g mouse-select-pane on; set -g mouse-select-window on" "set -g mouse on"
Sh (Bourne shell) shells:
is_pre_2_1="tmux -V | cut -d' ' -f2 | awk '{print ($0 < 2.1) ? "true" : "false"}'"
if-shell "$is_pre_2_1" "setw -g mode-mouse on; set -g mouse-resize-pane on;\
set -g mouse-select-pane on; set -g mouse-select-window on" "set -g mouse on"
Hope this helps
You can still using the devil logic of setting options depending on your current Tmux version: see my previous answer.
But since Tmux v1.7, set-option adds "-q" to silence errors and not print out anything (see changelog).
I recommend to use this feature, it's more readable and easily expandable.
Add this to your ~/.tmux.conf:
# from v2.1
set -gq mouse on
# before v2.1
set -gq mode-mouse on
set -gq mouse-resize-pane on
set -gq mouse-select-pane on
set -gq mouse-select-window on
Restar tmux or source-file your new .tmux.conf
Side note: I'm open to remove my old answer if people prefer this one
This line:
set -g mouse-mode on
in your ~/.tmux.conf file won't work.
For one thing, the proper setting is not mouse-mode, but mode-mouse.
Second, it only works on older versions of tmux (pre-version 2; you can run tmux -V to see what version you have, but you can also run man tmux to see if mode-mouse is a supported option).
And third, technically man tmux says to use the mode-mouse option with setw (set-window-option) and not with set (set-option), although I've seen it work with set (as well as setw).
These lines should work:
If your version of tmux is recent enough (that is, if tmux -V shows version 2 or newer), you can put this line in your ~/.tmux.conf file:
set-option -g mouse on
But if you use an older version of tmux, put these lines in your ~/.tmux.conf file:
set-window-option -g mode-mouse on
set-option -g mouse-resize-pane on
set-option -g mouse-select-pane on
set-option -g mouse-select-window on
Again, if you're not absolutely sure which line(s) to put in your ~/.tmux.conf file, run man tmux and search for mouse-mode, mouse-resize-pane, mouse-select-pane, and/or mouse-select-window. If you find them, then use those options (the ones for the older version of tmux).
Putting these lines in will allow you to use the mouse scroll wheel, it will allow you click on various panes to activate them, and it will allow you to resize panes just by clicking-and-dragging on their splitter separator.
You can also copy-and-paste using your mouse. However, you may notice that copying-and-pasting with your mouse may not work like it normally does on your console. To work around this, I've noticed that holding down the SHIFT key while using your mouse's copy/paste abilities makes them work normally again. (On MacOS, fn seems to work for me better than SHIFT.) Or you can learn tmux's approach to copy-and-pasting (which I do recommend).
A note on using tmux's native ability to copy/select/paste:
Personally, I feel that the vi keys make more sense to me than the default emacs keys (for example, it feels more natural to exit selection mode with vi mode's ENTER than with emacs mode's CTRL+w or ALT+w), so I have this in my ~/.tmux.conf file:
# For vi-like keys in copy/paste/selection mode:
set-window-option -g mode-keys vi
However, I've noticed that on older versions on tmux, this line won't work, unless I've also included the line:
set-window-option -g mode-mouse on
Good to know: Occasionally, when you're using the mouse's scroll wheel, you'll discover that your pane/screen appears to be frozen or locked up (it won't respond to keyboard input), and it's not clear what to do to unlock it.
It's not locked up. You're likely in tmux's selection mode. To get out of it, try one of these:
Hit ENTER. (Will likely work in vi mode.)
Hit ALT+w. (Will likely work in emacs mode.)
Hit CTRL+w. (Will likely work in emacs mode.)
Hit META+w. (Will likely work in emacs mode.)
Hit Esc. (Will likely work in emacs mode.)
Hit q. (Will likely work in vi mode, and may work in emacs mode as well.)
Ultimately, you can try hitting:
CTRL+w     ENTER
or:
Esc     q
Chances are, that will put you back in the normal mode where your keyboard is responsive again.
Using the mouse with vim:
I've discovered that putting this line in my ~/.vimrc file:
:set mouse=a
seems to work well with tmux, better than this line:
:set mouse=r
I can't really explain the difference; if you're a vim user, try them out and see which setting works best for you.
If you need to test out these tmux options, you may find yourself editing your ~/.tmux.conf file, exiting tmux, and then restarting tmux. This can become a tedious process, so if you want some work-arounds, here are some options:
Option1: After editing (and saving) your ~/.tmux.conf file, run this command (while in tmux):
CTRL+B :source-file ~/.tmux.conf ENTER
This will immediately apply the new settings in your ~/.tmux.conf file into your current tmux session, without the need to restart tmux.
Option 2: If you're in a tmux session, you can turn on/off options temporarily just for that session by running commands like these at the Unix shell prompt:
tmux set-option -g mouse on
tmux set-window-option -g mode-keys vi
Option 3: You can also temporarily turn on/off options in a tmux session with:
CTRL+B :set-option -g mouse on ENTER
CTRL+B :set-window-option -g mode-keys vi ENTER
Good luck, and have fun using tmux !
Try this. It works on my computer.
set -g mouse on
Ctrl + B and then set mouse. -g is not needed anymore.

Resources