Tmux Plugin Manager

What is Tmux Plugin Manager

Tmux Plugin Manager (TPM for short) is - as its name more than suggests - a way to handle plugins to tmux. Both the plugin manager and the plugins it manages are pretty much just shell scripts - you get nothing here, that you could not have written yourself. However you get both the conveinience of a simple plugin manager, and the flexibility to easily extend its functionality.

Why would you use it

If you - like me - live in the terminal, you will probably have more than one tmux session at a time, and probably have a lot of opinions on how it is to be setup. Most probably you will have a quite extensive tmux conf file. I had that as well.

My conf file is now very easy to understand, since all my setup has been placed into plugins. This means that my tmux.conf only contains the minimum code needed to load tpm and its plugins.

<code class="language-bash"><span class="nb">set</span> -g <a <span class="nv">href</span><span class="o">=</span><span class="s1">'https://github.com/resurrect-processes'</span> <span class="nv">class</span><span class="o">=</span><span class="s1">'user-mention'</span>>@resurrect-processes</a> <span class="s1">'"~gitsh->gitsh" irb pry "~rails s" "~rails server" "~rails c" "~rails console" "redis-server->redis-server" "grunt->grunt server" "foreman:->foreman start" "~tools/main.js mongo->meteor mongo" "~tools/main.js->meteor" "mongod->mongod"'</span>
<span class="nb">set</span> -g <a <span class="nv">href</span><span class="o">=</span><span class="s1">'https://github.com/resurrect-strategy-vim'</span> <span class="nv">class</span><span class="o">=</span><span class="s1">'user-mention'</span>>@resurrect-strategy-vim</a> <span class="s2">"session"</span>
<span class="nb">set</span> -g @tpm_plugins <span class="s2">" \</span>
<span class="s2">  tmux-plugins/tpm \</span>
<span class="s2">  clauswitt/tmux_layout \</span>
<span class="s2">  clauswitt/tmux_keybindings \</span>
<span class="s2">  clauswitt/tmux_mode_mouse \</span>
<span class="s2">  clauswitt/tmux_split_nav \</span>
<span class="s2">  tmux-plugins/tmux-sensible \</span>
<span class="s2">  tmux-plugins/tmux-sessionist \</span>
<span class="s2">  tmux-plugins/tmux-yank       \</span>
<span class="s2">  tmux-plugins/tmux-copycat    \</span>
<span class="s2">  tmux-plugins/tmux-resurrect \</span>
<span class="s2">  tmux-plugins/tmux-sidebar \</span>
<span class="s2">  tmux-plugins/tmux-logging \</span>
<span class="s2">  tmux-plugins/tmux-open \</span>
<span class="s2">  tmux-plugins/tmux-online-status \</span>
<span class="s2">  tmux-plugins/tmux-battery \</span>
<span class="s2">"</span>
run-shell ~/.tmux/plugins/tpm/tpm</code>

Installing

The last line in the above script is actually enough (assuming you have tpm placed at the same location as I have). Go to https://github.com/tmux-plugins/tpm and follow the instructions there - and you will be up and running in no time.

Installing Plugins

Installing plugins is as easy adding them to the tpm_plugins list (also shown in my tmux.conf file) - then hitting ctrl-b+I to install them.

Best Plugins

The plugins I use the most - apart from the ones prefixed with clauswitt/ above (which has my personal preferences) are as follows.

Sessionist

This plugins lets you jump to sessions much faster than the built-in list (ctrl-b+s). Located at ctrl-b+g it will show you a list that looks pretty much like the built in one, however instead of having to scan the list, and finding the correct hotkey to press to get to that session, you can fuzzy type its name. You just have to type enough of the name for it to be unique, and you can jump there in no time.

On top of that you get a ctrl-b+S to jump to last used session (it is default ctrl-b+L in tmux, however most people remap this to resize panes instead).

Yank

Tmux yank is well, better yanking for your tmux session. In visual (or selection as I think is its real name) mode it will let you press y to yank to system clipboard. ctrl+y to yank directly to stdin (meaning if you have highlighted a previous command for instance, you can press ctrl+y to have it “typed” as the current command). Last but not least you can use alt/meta+y to get both (yanked to clipboard, and inserted into terminal).

However where yank really shines is in combination with:

Copy Cat

Copy cat is a plugin which lets you do regex search in your current tmux pane, and highlights current selection based on that search. Anything highlighted can be copied (and thus put directly into the terminal prompt) by the yank plugin.

Copy cat comes with some built-in searches (which are the ones I use 9 out of 10 times).

  • ctrl-b+f searches for stuff that looks like file names

  • ctrl-b+g searches for stuff that matches files in a git status command output

  • ctrl-b+u searches for stuff that looks like urls

For all three you can yank directly to current command prompt by pressing ctrl+y. I use this alot for running diffs on staged files in a git status. Or opening (ctrl+o, if you have the tmux-open plugin installed) an url or file with the default browser/program.

Resurrect

This is what convinced me to try out tpm. And I have loved it ever since. Save your complete list of sessions, windows and panes into a simple textfile, and have this plugin resurrect it all. This means that your tmux sessions (seems to) persist event a restart of the computer.

The _resurrect-processes_variable in my tmux.conf file, tells the plugin what processes to resurrect (apart from the default ones) and what command to run to get them back. It does not work with everything - but most of what I work with is supported out of the box.

It even starts vim with the -S flag, so if you use vim sessions (and if you don’t look into it, and install Tim Popes Obsession plugin to manage it). Meaning that each vim in any pane or window are started where they left of.

You need to store session/window/pane/layouts manually though: ctrl-b+s to save, and ctrl-b+r to resurrect.

Make your own plugin

If you want to make your own plugin, it is super easy. An easy way to get started is to extract all your theme stuff (assuming you don’t roll with the standard look and feel of tux) into a plugin.

Take a look at the existing plugins. You’ll find that most of them (if not all) are just some keybindings in a tmux file, which sometimes call script files written (mostly) in bash-script.