Ceci est une ancienne révision du document !
In the previous articles, we have learned what the tmux application is, how to install it, and what are the basics - in order to be able to command it. We know the window and pane handling as well. This knowledge is quite enough for daily usage to make our life simpler. Now we will learn how to customize the tmux environment to suit our personal wishes. All of the utilization can be performed in the tmux configuration file. This is a human readable plain text file. Two places can be used - depending on the purpose of user range: /etc/tmux.conf - for all users ~/.tmux.conf - for current user only The exact place of the global configuration file depends on the operating system in use. In GNU/Linux, this is the “etc” directory, but, to be sure, the man page of tmux can be read that deals with the -f parameter. Also note that the current user level file is a hidden file; its name starts with a dot character.
Dans les articles précédents, nous avons appris ce qu'est l'application tmux, comment l'installer et ce que sont les base - de façon à être capable de le commander. Nous connaissons aussi la gestion des fenêtres et des panneaux. Ce savoir est pratiquement suffisant dans un usage quotidien pour rendre votre vie plus simple. Maintenant, nous allons apprendre comment personnaliser l'environnement tmux pour correspondre à vos souhaits personnels.
Toute l'utilisation peut être réalisée dans le fichier de configuration de tmux. C'est un fichier texte brut, lisible par un humain. Deux endroits peuvent être utilisés - suivant l'étendue de l'application aux utilisateurs :
/etc/tmux.conf - pour tous les utilisateurs
~/.tmux.conf - pour l'utilisateur actuel seulement
La place exacte du fichier de configuration globale dépend de votre système d'exploitation utilisé. Dans GNU/Linux, c'est le répertoire « etc », mais, pour s'en assurer, la page man de tmux peut être lue qui parle du paramètre -f. Notez aussi que le fichier au niveau de l'utilisateur courant est un fichier caché ; son nom commence par un point.
General settings Let's start with some general attributes. The most common modification is the change of the Prefix command. Default is the <Ctrl b>. The problem with this is that the “b” character is far away from the Ctrl key. The widely used setting is the <Ctrl a> for Prefix. Additionally, most users change the Caps Lock key to behave as Ctrl key. With this further change, the Prefix command is quite adequate. The new <Ctrl a> combination can be used by other applications as well (e.g.: in vim, it increases a numeric value), therefore we have to care about that as well. # Setting the <Prefix> command from <Ctrl-b> to <Ctrl-a> set -g prefix C-a # Release the original <Ctrl-b> <Prefix> keybinding unbind C-b # Ensure that <prefix> combination can be sent to other apps by pressing it twice bind C-a send-prefix We can modify the escape key delay value, and make the tmux more responsive. By default it is 500ms, and this can be frustrating, for example in Vim. # Setting the escape delay to be more responsive set -s escape-time 1
Paramètres généraux
Commençons par des attributs généraux. La modification la plus classique consiste à changer la commande Préfixe. La valeur par défaut est <Ctrl b>. Le problème avec ceci est que la touche b est éloignée de la touche Ctrl. Le réglage largement utilisé pour Préfixe est <Ctrl a>. De plus, la plupart des utilisateurs changent la touche <Caps Lock> pour qu'elle serve de touche <Ctrl>. Avec ce dernier changement, la commande Préfixe est presque idéale. La nouvelle combinaison <Ctrl a> peut être aussi utilisée par d'autres applications (par ex., dans vim, ça augmente une valeur numérique) ; ainsi donc, nous avons aussi à la prendre en compte.
# Paramétrer la commande « Préfixe » de <Ctrl b> vers <Ctrl a> set -g prefix C-a # Abandonner la combinaison de touches de la commande « Préfixe » <Ctrl b> d'origine unbind C-b # S'assurer que la combinaison de « Préfixe » peut être envoyée à d'autres applis en appuyant deux fois dessus bind C-a send-prefix
Nous pouvons modifier la valeur de délai de la touche <escape> et rendre tmux plus réactif. La valeur par défaut est 500 ms et elle peut être frustrante, par exemple dans vim.
# paramétrer le délai de la touche <escape> pour la rendre plus réactive set -s escape-time 1
Generally the content of the tmux.conf file is loaded only during start-up of the program. The effect of any changes in the configuration file will have effect after restarting tmux. This is not so cool during the customization, therefore we will create a command binding <Prefix r> to be able to load the configuration file when we wish (keybinding is detailed in the next section). Additionally, the execution of the command will be signed with a message in the status bar. # Reload the configuration file with <Prefix r> bind r source-file ~/.tmux.conf \; display “Configuration reloaded!” As mentioned in the previous article, the numbering of the windows and panes starts from 0. This can be set to start from 1 for easier human processing. # Setting the base index for windows to 1 instead of 0 set -g base-index 1 # Setting the base index for panes to 1 instead of 0 set -g pane-base-index 1
Généralement, le contenu du fichier tmux.conf n'est chargé que pendant le démarrage du programme. Les effets de tous les changements dans le fichier de configuration n'auront d'effet qu'après le redémarrage de tmux. Ce n'est pas terrible pendant la personnalisation ; aussi, nous créerons la combinaison de commande <Préfixe r> pour être capables de charger la configuration quand nous le souhaitons (la combinaison de touches est décrite dans la prochaine section). De plus, l'exécution de la commande sera signalée avec un message dans la barre de statut.
# Recharge du fichier de configuration avec <Préfixe r> bind r source-file ~/.tmux.conf \; display “Configuration rechargée!”
Comme indiqué dans l'article précédent, la numérotation des fenêtres et des panneaux commence à 0. Elle peut être modifiée pour commencer à 1 pour faciliter le traitement par l'homme.
# Paramétrage de l'index de base pour les fenêtres à 1 plutôt que 0 set -g base-index 1 # Paramétrage de l'index de base pour les panneaux à 1 plutôt que 0 set -g pane-base-index 1
A big advantage of tmux is the mouse-free handling. Despite this, tmux has mouse support, but the availability of this feature can force us to really use it. Therefore my opinion is to disable it explicitly. # Setting the mouse support to off set -g mouse off It is also disturbing (at least for me) when tmux notifies us of every activity in a window. It can be also disabled. # Setting the activity monitoring to off setw -g monitor-activity off set -g visual-activity off Now the general settings are done. Of course, it can be extended as you wish, but for the first shot, these are quite enough for a comfortable usage.
Custom bindings There are some tmux commands which have an uncomfortable key code. The tmux configuration provides a very simple method to override the default mapping (we have already used it in the previous section). It is called binding, and the “bind” command can be used for this purpose. Most tmux users change them according to personal preferences. I share with you my customization; feel free to override them. It is much easier to remember the new commands of the window split combination as they are visually matching their functionality. # Splitting panes with | and - bind | split-window -h bind - split-window -v Most people will use the panes. Moving between them has to be as simple as possible, therefore the elimination of the Prefix key (-n), and the usage of the arrow keys, are the best combination. # Moving between panes with <Alt arrow> without Prefix bind -n M-Left select-pane -L bind -n M-Down select-pane -D bind -n M-Up select-pane -U bind -n M-Right select-pane -R
Sometimes, resizing of the panes is also necessary; this new combination is simpler. With the repeating feature (-r), the last key press is enough to continue the resizing of the corresponding pane. The number at the end means the amount of the resize; 2 pixels in our case. # Resizing the panes with <prefix H,J,K,L> by repeating feature bind -r h resize-pane -L 2 bind -r j resize-pane -D 2 bind -r k resize-pane -U 2 bind -r l resize-pane -R 2 Moving between windows is mapped to the <Prefix m> (next window) and <Prefix n> (previous window) commands. # Quick window selection bind -r m select-window -t :+ bind -r n select-window -t :-
Colors After the previous settings, we can concentrate on another aspect of tmux: the visual style. The environment colors and status bar information content are as important for a daily user as the commands. The settings can be made by the “set” command. The -g option means that it is valid for all sessions. The desired colors can be set with the “colourNNN” command where the NNN is the number of the predefined colors of 256-color mode. First of all, the base colors can be defined for better readability. My personal style is to use different gray tones. Almost every part of the environment can be modified: status bar, window list, pane borders, active and inactive panes, command/message line. The code (previous page, top right) contains my configuration; the comments describe the exact effect of the settings. The picture shows the result of the color change.
Status bar The default status bar is not a big deal. It contains only the basic information in an ugly way. On the internet, a lot of layouts can be found; you can choose one or you can use mine. I have created an own version that meets my needs. First, the refresh rate is modified from the default 15 seconds to 5 seconds, with this I get more up-to-date information about my system. # Setting the refresh rate in seconds set -g status-interval 5 The default length of the status bar parts (left and right) is not enough for the desired information, therefore it has to be overridden. # Setting the length of the status bar set -g status-left-length 100 set -g status-right-length 100
The left part of my status bar is set to green and it contains: • the host name of the system, • the name of the session. The list of the opened windows is right-aligned, and the active one has a gray background. The right part of my status bar contains: • the CPU load values, • the memory (RAM) status, • the used disk space in MB and in %, • the current date and time with gray background for better readability. The result can be seen in the picture within this article. In this part of the configuration (above), I also use some constants for better readability.
Finalization We have finished the first steps. I hope it was a pleasant trip and you are ready to use this amazing tool in your daily work. Of course, these articles did not cover all of the aspects of the tool, and also the covered parts are more sophisticated, so feel free to use the manual page of tmux, or the web, to get more information and customization possibilities. But I am sure that this is the minimum knowledge to start mouse-free development, and the content of the articles is enough to be more effective. Finally let me to propose a fantastic book regarding this topic: Brian P. Hogan: tmux 2 ISBN-13: 978-1680502213 ISBN-10: 1680502212 https://www.amazon.com/tmux-2-Productive-Mouse-Free-Development/dp/1680502212 This book covers the topics of my three articles, but with more samples, and deeper and more detailed screenshots. Additionally, it writes about (from the table of contents of the book): • Scripting customized tmux environments • Working with text and buffers • Pair programming with tmux • Workflows Get Productive! Get tmux!