I am mainly working in a terminal and so it happen that I need more than one session to do my work.
There a good Terminal emulators like Konsole or Gterm, where you have the possibility to use tabs and/or multiple windows to organize your different sessions. But sometimes you need two or more session visible in parallel open, or you have some longterm processes on a remote machine. In this case you have for each task a single window, or tab open and this may clutters the desktop and you maybe become overwhelmed.
To have a little bit more control, i am using a terminal multiplexer like tmux. There are other multiplexer as well, but i didn't spend time that much to evaluate all of them. The famous ones, beside of tmux
are e.g. screen
or terminator
.
With tmux you get the possibility to have multiple terminal sessions in a single window this can look like this:
In this example you see four panes.
| htop |
| vim | second vim instance | build in tmux clock |
But you can see more.
I have multiple tabs which could containing multiple panes as well.
But my work flow is following some specific rules. This are only followed, if the session is long living, or I know, I need it over a long period of time.
E.G when I am programming with Vim, I am renaming the current window with the project name, or something which shows me in which project context this window is.
In special cases, E.G I am on support and need multiple sessions for holding my ssh connection, I rename the whole session, and the windows names containing the ssh targets.
So the most common key bindings are:
prefix c create window
prefix w list windows
prefix n next window
prefix p previous window
prefix f find window
prefix , name window
prefix $ name session
prefix x kill window
# some custom bindings
prefix | # vertical split
prefix - # horizontal split
ctrl h # switch pane left
ctrl j # switch pane down
ctrl k # switch pane up
ctrl l # switch pane right
I have some plugins as well.
tmux-plugins/tmux-urlview
allows me to list all URLs in a separated pane and let me choose which one I want to open in my browse.
tmux-plugins/tmux-resurrect
allows me to save all my sessions and panes, so that I can restore my layout.
To switch seamlessly between tmux panes and vim splits,I have following settings:
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'
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
I changed the default prefix key as well. The default is ctrl+b
, but this is not very handy. I use instead ctrl+a
, which is quite common.
If you want to have a close look at my configuration you can find it here.
Top comments (0)