.tmux.conf

Posted on Wednesday, January 21, 2015



I have a custom config for gnu screen, my .screenrc.  Knowing how much a few tweaks helps gnu screen work so much better I decided to figure out how to configure tmux's .tmux.conf file.   

When tmux starts it will look for a custom configuration file at ~/.tmux.conf

If you don't have have tmux installed I wrote up a guide at http://www.whiteboardcoder.com/2014/12/installing-tmux.html  that shows how to install it on Ubuntu (10.04, 12.04, and 14.04), OSX via brew, and even cygwin.





Create the .tmux.conf file and start tweaking.


     > vi ~/.tmux.conf


First things first, Ctrl+b is a bit of a pain, it’s a long way to reach for on a keyboard, and I used to using Ctrl+a from gnu screen.  I am going to change it to Ctrl+a to save my fingers and to match my gnu screen memory muscles.



set -g prefix C-a
bind C-a send-prefix



This will set the prefix -g (Globally)




One way to reload the changes is to start or reattach to a tmux session and press Ctrl+b then ":" then type the following command


  source-file ~/.tmux.conf





The next time you could user Ctrl+a then ":" or Ctrl+b then ":" since I did not unbind the other prefix.






List all the bindings


To list all the current bindings press Ctrl+a then ?



You can see the C-a key that was bound at the top.
To exit this mode press Ctrl+c

Another way to get this list is to run the following command


     > tmux list-keys




Another useful command is


     > tmux show-options -g


This will list all the current global options.





In the book tmux: Productive Mouse-Free Development by Brian P. Hogan [1] (I think is a good book to buy, it gets you from a beginner to an advanced tmux user)  it suggest a few bindings I thought were good to add so I did. 



Here is my .tmux.conf file


set -g prefix C-a
bind C-a send-prefix

#Bind new split commands
bind | split-window -h
bind - split-window -v

#Set status bar on bottom
set -g status-left 'tmux'
set -g status-right '(Pane #P) #{=22:pane_title}" %H:%M %d-%b-%y'

#Highlight the name of the selected window
set -g window-status-current-fg white
set -g window-status-current-bg red
set -g window-status-current-attr bright

set -g window-status-bg green
set -g window-status-fg black
set -g window-status-attr dim

#Borders
set -g pane-border-fg green
set -g pane-border-bg black
set -g pane-active-border-fg white
set -g pane-active-border-bg yellow

#Mouse turned on give ability to click on pane
setw -g mode-mouse on
set -g mouse-select-pane on
set -g mouse-resize-pane on
set -g mouse-select-window on



I am going to explain what is going on section by section here.


#Bind new split commands
bind | split-window -h
bind - split-window -v


I added the ability to split the screen using Ctrl+a then | (for vertical) and - (for horizontal)


#Set status bar on bottom
set -g status-left 'tmux'
set -g status-right '(Pane #P) #{=22:pane_title}" %H:%M %d-%b-%y'


This changes the text displayed on the bottom.



Now it has "tmux" on the far left.  And (Pane X) on the right hand side (far left of the right hand side).  The Pane X displays which pane # you are on.





#Highlight the name of the selected window
set -g window-status-current-fg white
set -g window-status-current-bg red
set -g window-status-current-attr bright

set -g window-status-bg green
set -g window-status-fg black
set -g window-status-attr dim



The selected Window now has a red background and white lettering.  This helps to easily identify which window you are on.






#Borders
set -g pane-border-fg green
set -g pane-border-bg black
set -g pane-active-border-fg white
set -g pane-active-border-bg yellow



This is neat!  It will highlight the selected pane.



The lower left pane is selected.




#Mouse turned on give ability to click on pane
setw -g mode-mouse on
set -g mouse-select-pane on
set -g mouse-resize-pane on
set -g mouse-select-window on



Turn the mouse on!  Now you can use the mouse to select a window pain.  You can even click on the window name in the lower right to select another window.





References
[1]        tmux: Productive Mouse-Free Development
            Author: Brian P. Hogan
                Accessed 1/2015









This post is a part of and epic, the Tmux epic.


Epic Goal:   Learn how to use tmux to open 8 panes that each start to tail a different serverlog via ssh, all via a script.

No comments:

Post a Comment