How to use Tmux and personalize configuration

Source: Internet
Author: User
Tags ssh access

Introduced

Tmux is an excellent terminal reuse software, even if the non-normal drop line, but also to ensure that the current task runs, this is particularly useful for remote SSH access, the network is not a bad situation can still ensure that the work site is not lost! In addition, Tmux fully uses the Keyboard control window to achieve the window switching function.

To put it simply, Tmux has two main functions for me (this should also be the main function of Tmux):

    1. Split window. You can open multiple terminals under one terminal, or you can split the current screen in a variety of ways, so that you can open multiple terminals with smaller display ranges at the same time.
    2. In the use of SSH environment, to avoid network instability, resulting in the loss of the work site. Imagine the following scenario when you execute a command and the SSH connection is broken due to network instability. At this point, you don't know if the previous command was successful. If you open a lot of files at this time, into a deeper directory, due to network instability, SSH connection disconnected. After reconnecting, you have to reopen those files and enter that deep directory. If the use of Tmux, reconnect later, you can directly back to the original work environment, not only improve the efficiency, but also reduce the risk, increased security.
Installation
sudo apt-get install tmux

After the installation is completed, enter the command Tmux to open the software, the interface is very simple, similar to a terminal console with the status bar below; No accident, this time you will be the same as I did, think Tmux nothing.

Session, window, panel

Based on the definition of Tmux, when the Tmux server is turned on, a session is created first, and the session first creates a window that contains only one panel, that is, the so-called terminal console should be called a panel of Tmux, although it is used exactly the same way as the terminal console.

Tmux is constructed using the C/S model, which consists of the following modules:

    • Server servers. A server is turned on when you enter the Tmux command.
    • Session sessions. A server can contain multiple sessions
    • window. A session can contain multiple windows.
    • Pane panel. A window can contain multiple panels.
First Experience

Let's take a look first, then learn TMUX configuration and use I generally use this, because my notebook is only 13 inches:-)

frequently used keys It is important to note that any instruction in Tmux contains a prefix, that is, you press the prefix (a set of keys, the default is CTRL+b) Later, the system will know that your next instruction is sent to Tmux. C-B. Show shortcut key Help C-B c-o Swap window position, similar to the C-in vimW C-b SPACEBAR takes the next built-in layout C-b! Change the current window to a new window C-B"modulo divider WindowC-b%vertically separated window C-B Q shows the number of the separator window C-b o jumps to the next divider window C-b the upper and lower keys on the previous and next separator window C-B alt-Direction key Resize window size C-b C Create a new window C-B 0~9Select the number of Windows C-b C Create a new window C-b N Select the next window C-b L switch to the last used window C-b P Select Previous window C-b w Display in menu mode and select Window C-b t display clock C-b; Switch to the last used panel C-b x Close Panel CB &Close Window C-b S Display and select session C in menu mode-b D exit tumx, and save the current session, Tmux is still running in the background, you can go through the Tmux attach to the specified session configuration we first look at a few configurations, these configuration is why I can not leave Tmux:-)。 Tmux configuration file is ~/.tmux.conf, this file may not exist, you can create your own. The following start configuration, first, there is no feel tmux the prefix is too inconvenient, CTRL and B key isolated too far, many people map it into c+a, that is, in the configuration file (~/Add the following statement to the. tmux.conf):#set prefix to CTRL + aSET-G prefix CA at the same time, cancel the default prefix key:#To disassociate the ctrl+b from the prefixUnbind Cb after configuration, restart Tmux, or press C first+B, then enter:, enter command-line mode, input in command-line mode: source-file ~/. Tmux.conf you can also, like me, add the following sentence to the config file, and then change it by the prefix only+R now. #set R to load the configuration file and display "reloaded!" InformationBind r source-file ~/.tmux.conf \; Display"reloaded!"about prefixes, many people like to change to Ctrl+a, but I personally prefer ctrl+x, if you are a vim user, you must understand. There is the panel switch is not convenient, need to first press the prefix, and then press the direction key, remember how the vim inside how to switch the various panels? Tmux can also, because it supports mappings. Change the prefix mapping to CTRL +x, and then add the following several statements, now the switch window and vim a touch, immediately feel a lot of kindness. # upBind-key k Select-pane-U# DownBind-key J Select-pane-D# LeftBind-key H Select-pane-L# RightBind-key L Select-pane-the last statement above the R will change the C-x L function, I like this function, because we are very often in two windows or the two panels switch, so I added the following statement#Select Last WindowBind-key c-l Select-window-L Now I can not press the L key, Ctrl+x l is a toggle panel, ctrl+x ctrl+l Switch window, CTRL +l clear the screen. Copy a mode copy-mode prefix [Enter copy mode press space to start copying, move cursor Select Copy area press Enter to copy and exit copy-mode. Move the cursor to the specified position, press Preifx] paste if we compare Tmux to Vim, then most of our time is in the editing mode, we can copy the same time as vim to move it? You only need to use the configuration file (~/Add the following line to the. tmux.conf). #Copy-mode Set the shortcut key to VI modeSetw-g mode-Keys VI session C-x S view and select Session C as a menu-x:new-session Create a new conversation C-x D exit and save session terminal run TMUX attach return session naming session Tmux new-s Sessiontmux New-S session-d#establish a session in the backgroundTmux ls#List SessionsTmux ATTACH-T Session#Enter a sessionmaximize current Pane from the moment I start with vim, I believe there are people in the world who know what you want more than yourself, so Joe can make a product that screams the world, So I often browse the master's. vimrc file, I used tmux less than 3 days to find out, how can it not maximize the current pane? Just like the Zommwinplugin.vim plugin in vim, you press a key and the current window is maximized to get the maximum visual interface. So far, I have not found that I have the demand and others do not, the same, has been found by the previous solutions, the method is as follows:#Zoom pane <-> window#http://tmux.svn.sourceforge.net/viewvc/tmux/trunk/examples/tmux-zoom.shBind ^z Run"Tmux-zoom"##Scroll screen to enter copy-mode, which is the prefix +[, then you can use the up and down keys to scroll the screen, the configuration of the VI shortcut key mode, you can do the same as the VI to scroll the screen, very convenient. Exit directly by pressing ' Q ' key. Other configuration below is extracted from other people's configuration, anyway, I do not need to keep the reference bar, perhaps the screen before you need it. ##author:xu xiaodong <[email protected]>#modified:2012 Jul##--Base settings--#Set-g default-terminal"Screen-256color"Set-G Display-time 3000Set-G escape-Time 0set-G History-limit 65535Set-G Base-index 1Set-G Pane-base-index 1#--Bindkeys--##prefix key (Ctrl + a)Set-g prefix ^Aunbind^bbind a Send-prefix#Split WindowUnbind'"'#Vertical split (prefix-)BIND-SPLITW-Vunbind%Bind| Splitw-h#horizontal split (prefix |)#Select PaneBind K Selectp-u#above (prefix k)Bind J selectp-d#below (prefix j)Bind h Selectp-l#Left (prefix h)Bind L Selectp-r#Right (prefix L)#Resize PaneBind-r ^k resizep-u 10#upward (prefix ctrl+k)Bind-r ^j resizep-d 10#downward (prefix ctrl+j)Bind-r ^h resizep-l 10#To the left (prefix ctrl+h)Bind-r ^l Resizep-r 10#To the right (prefix ctrl+l)#Swap Pane#swap with the previous pane (prefix ctrl+u)Bind ^u Swapp-U#swap with the next pane (prefix ctrl+d)Bind ^d Swapp-D#Misc#Select the last pane (prefix e)bind e LASTP#Select the last window (prefix ctrl+e)Bind ^e Last#Kill pane (prefix q)bind Q KILLP#Kill window (prefix ctrl+q)Bind ^Q KILLW#Copy Mode#Enter copy mode (prefix Escape)Bind Escape copy-Mode#paste buffer (prefix ctrl+p)Bind ^P Pasteb#Select (v)Bind-t Vi-copy v begin-selection#copy (y)Bind-t vi-copy y copy-selection#Zoom pane <-> window#http://tmux.svn.sourceforge.net/viewvc/tmux/trunk/examples/tmux-zoom.shBind ^z Run"Tmux-zoom"#app#htop (prefix!)bind! SPLITW htop#Man (prefix m)Bind M Command-prompt"SPLITW ' exec man percent '"#perl func (prefix @)Bind @ command-prompt"SPLITW ' exec perldoc-t-f percent '"#perl var (prefix *)Bind * Command-prompt"SPLITW ' exec perldoc-t-v -percent '"#perl doc (prefix%)Bind% Command-prompt"SPLITW ' exec perldoc-t percent '"#Ruby doc (prefix/)Bind/command-prompt"SPLITW ' exec ri percent '"#Reload config (prefix r)Bind r source ~/.tmux.conf \; Display"Configuration reloaded!"#--StatusBar--#Set-g status-UTF8 onset-G Status-interval 1Set-G status-Keys VISETW-G mode-Keys VISETW-G automatic-Rename off#--ColorScheme--##https://github.com/daethorian/conf-tmux/blob/master/colors/zenburn.conf#ModesSetw-g clock-mode-Colour COLOUR223SETW-G mode-attr BOLDSETW-G mode-FG COLOUR223SETW-G mode-BG colour235#panesSet-g pane-border-BG Colour234set-G pane-border-FG Colour234set-G pane-active-border-BG Colour232set-G pane-active-border-FG colour232#StatusBarSet-g status-Justify Centreset-G status-BG Colour235set-G status-FG Colour248set-G status-attr Dim#[default]? #[fg=colour187] #S #[default]? #[fg=colour187]w#i.p#p#[default] "Set-g Status-left"Set-g status-left-attr Brightset-G Status-left-length 20#[fg=colour174]# (/home/xiaodong/bin/uptime) #[default]? #[fg=colour174]# (cut-d "-F 1-3/proc/loadavg)"Set-g Status-right"Set-g status-right-attr Brightset-G Status-right-length 80SETW-G window-status-current-FG COLOUR223SETW-G window-status-current-BG COLOUR237SETW-G window-status-current-attr BOLDSETW-G Window-status-current-format"#I: #W #f"#setw-g window-status-alert-attr Bold#setw-g WINDOW-STATUS-ALERT-FG colour255#setw-g WINDOW-STATUS-ALERT-BG colour160#MessagesSet-g message-attr Boldset-G message-FG Colour223set-G message-BG Colour235set-G visual-activity on Quick Start tmux If you think you need to open tmux every time, and then open a few windows and panels is very troublesome, then the following script you will love. Refer here#!/bin/sh##Name:tmuxen, Tmux Environment made easy#Author:xu Xiaodong [email protected]#LICENSE:GPL#created:2012 Jul#modified:2012 Jul#cmd=$ (which Tmux)#Tmux PathSession=codefun#Session Nameif[ -Z $cmd]; Then Echo"You need to install Tmux."Exit1Fi$cmd has-T $sessionif[ $? !=0]; Then $cmd new-d-n vim-s $session"Vim"$cmd SPLITW-v-p 20-t $session"Pry"$cmd neww-N mutt-t $session"Mutt"$cmd neww-N irssi-t $session"Irssi"$cmd neww-N cmus-t $session"CMUs"$cmd neww-N zsh-t $session"zsh"$cmd SPLITW-h-p 50-t $session"zsh"$cmd selectw-T $session: 5fi$cmd att-T $sessionexit 0 if there are other needs, you can go here and see, of course, the most comprehensive reference document, is Man Tmux. Happy tmux!

How to use Tmux and personalize configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.