[Linux] tmux installation (non-root) and its use

tmux (terminal multiplexer) are multiplexed on Linux terminal artifact.

1. Install

(1) Download

Download the software and its dependencies.

wget -c https://github.com/tmux/tmux/releases/download/3.0a/tmux-3.0a.tar.gz
wget -c https://github.com/libevent/libevent/releases/download/release-2.1.11-stable/libevent-2.1.11-stable.tar.gz
wget -c https://ftp.gnu.org/gnu/ncurses/ncurses-6.2.tar.gz

(2) Installation

First install dependencies, then install tmux.

#libevent
./configure --prefix=/my/path/tmux_depend --disable-shared
make && make install

#ncurses
./configure --prefix=/my/path/tmux_depend
make && make install

#tmux
./configure CFLAGS="-I/my/path/tmux_depend/include -I/my/path/tmux_depend/include/ncurses" LDFLAGS="-L/my/path/tmux_depend/lib -L/my/path/tmux_depend/include/ncurses -L/my/path/tmux_depend/include" 

#CPPFLAGS="-I/my/path/tmux_depend//include -I/my/path/tmux_depend//include/ncurses" LDFLAGS="-static -L/my/path/tmux_depend//include -L/my/path/tmux_depend//include/ncurses -L/my/path/tmux_depend//lib" 

make
cp tmux  /my/path/tmux_depend/bin

(3) set up the environment

Set environment variables.

#bashrc
export PATH=/my/path/tmux_depend/bin:$PATH
source ~/.bashrc

2. Use common commands

tmux structure comprises a session (the session), the window (window), the pane (Pane) of three parts, the session is a set of pseudo terminal essence, each pane represents a dummy terminal, a plurality of panes presented on the screen, which a screen called windows.

image.png

The following is an excerpt from a blog post tmux basic operations , well-written, but if not a little bit of foundation, ignores many places. Avoid walking pit, focusing explain.

The basic operation is nothing more than tmux session, window panes manage, including create, close, rename, attach, detach, etc. selected.

Command and shortcut keys are generally used to operate the terminal and may tmux system shell command mode (similar to vim command mode, the window with the text) using the command, or use the shortcut keys tmux terminal.

The default shortcut tmux prefix Ctrl + b ( hereinafter, refer to a prefix ), press the key combination prefix release (release note and then press the key combination!) , then press the shortcut key commands, such as separation of the session (d instead of prefix is prefix + d, as d + b not key pressed together with the Ctrl! ). So the following prefix + B equal Ctrl / A .

Shortcut keys can be customized, such as Ctrl + a prefix to smoothly number ( if an invalid key press ctrl b, the check ~ / .tmux.conf configuration file or whether to replace the masked, A may try Ctrl ). If you need to retain the shell commands Ctrl + a shortcut (i.e. jump to the beginning of the line), modified ~ / .tmux.conf file as follows:

1 set-option -g prefix C-a
2 unbind-key C-b
3 bind-key C-a send-prefix
4 bind-key R source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."

Now has a shell with Ctrl + a prefix Ctrl + a substitution that need to press Ctrl + a twice to take effect (skip to beginning of the line).
Effect of the fourth line is used to reload the configuration file prefix r, and outputs the prompt. Otherwise, the need to close the session configuration file to take effect , can also be manually load the configuration file, the input terminal tmux "prefix:" into the command mode (note the colon), load the configuration file with source-file command .
Note that multiple commands together as a write command sequence, use a space between the command and separated by semicolons.

(1) Session Commands

  • tmux new name creates a default session
  • tmux new -s mysession create a session called mysession
  • tmux ls displays a list of conversations
  • tmux a session connection
  • tmux a -t mysession specified session connection
  • tmux rename -t s1 s2 s1 to s2 session rename
  • tmux kill-session close the last open session
  • tmux kill-session -t s1 s1 Close Session
  • tmux kill-session -a -t s1 s1 close all sessions except the
  • tmux kill-server closes all sessions
  • tmux list-key lists all key bindings, equivalent to a prefix?
  • tmux list-command lists all commands

Common shortcuts: press after the prefix

  • s listed session can be switched
  • $ Rename Session
  • d separating the current session
  • D specifies separate session

(2) Window command

Common shortcuts: press after the prefix

  • c create a new window
  • Rename the current window
  • w lists all windows can be switched
  • n go to the next window
  • p go to the previous window
  • Before entering the operation of the window l
  • 0 ~ ~ 9 0 9 selection numbers corresponding to the window
  • Modify the current window index number
  • 'To switch to the designated number (may be greater than 9) of the window
  • f search pane according to the content displayed
  • & Close the current window

    (3) command pane

    Common shortcuts: press after the prefix
  • % Create horizontal panes
  • "Create a vertical pane
  • Up | Down | Left | Right pane switched according to the direction of the arrow
  • q display pane numbers
  • o pane clockwise switch
  • } And the next pane exchange position
  • {With the switching position of a pane
  • x Close the current pane
  • space (spacebar) rearranges all the current window pane
  • ! The current pane placed in a new window
  • Ctrl + o is rotated counterclockwise current window pane
  • display time t in the current pane
  • z amplifying the current pane (pressed again restored)
  • Information pane displays the current i

Startup and Shutdown server

tmux # 启动 
tmux kill-server # 关闭

Enter and exit the session

tmux attach 
prefix d # 或者 prefix C-z

3. Configure Shortcuts

Configuration About ~ / .tmux.conf file, there is a tutorial can refer to:
[tmux commonly used shortcuts and some of the issues I will be haunted summary] (https://www.cnblogs.com/piperck/p/4992159. html)
or:
[tmux using methods and customized configuration] (https://www.cnblogs.com/chjbbs/p/5689011.html)

tmux use and personalized configuration

But the online tutorial in most configurations are too old, not a lot of recognition. So you can not copy to use, it is best they used prefix ?to see. For example, use the mouse to control the windows and panes of different size (drag) to control (the vast majority of online tutorials, useless) version 2.0 and below by the following settings:

setw -g mouse-resize-pane on  #(或者set)
setw -g mouse-select-pane on
setw -g mouse-select-window on
setw -g mode-mouse on

Tmux2.0 version used above set -g mouse oncan be. More Settings window scroll mouse back and forth reference:

# Enable mouse mode (tmux 2.1 and above)
set -g mouse on

#Enable oh my zsh in tmux
set -g default-command /bin/zsh

# Mouse based copy
bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key -T copy-mode MouseDragEnd1Pane send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy" 

4. problem

Although it is convenient to split the window, but when you copy a text window with the mouse to another window, copy inconvenient, since multiple windows of the same line is still regarded as one line, it is more difficult to copy. For example, when I want to copy a long path (double-click can not be copied), more difficult, and when you switch to paste too much trouble:
image.png

Some online solutions, such as: the selection pane, prefix z, copy, prefix z, switching pane paste . When does too much trouble. Follow-up look at shortcuts can not get rid of, or defects in this function directly Let me think either use it.

One-way replication to solve the problem through different windows to configure the mouse, single-line display but is still seen as range display line (regarded as beyond the scope of another line, still can not replicate). Mouse selection replication difficult to solve, but the demand is too important, I often have to copy and paste long strings of the path, which is the reason why I use multiple terminals, if this is not a good solution, I'd rather not up!

So, now I use the configuration is: If you want to use as normal terminal, namely the mouse to copy (double left click) Paste (right-click) operation, but only one-way screen copy and paste, the configuration is set to version 2.0 of the following modes ; if you want to use the mouse to drag the pane free size, scrolling pane, the pane chosen at random mouse and other operations, it is set to version 2.0 or higher mode, that is set -g mouse on, but you can not copy and paste selected.


final plan:

To copy a long path (mouse), not entangled with the method of cutting a window, a new multi-window, and then prefix n/pswitch back and forth copy and paste. Therefore, if the back and forth with the operation, a method can be used in different switching paths window; if in the same path, the cutting window (as in a write code pane, a pane debug resources or top view). Of course, also a plurality of new session, and then switch between different session ( prefix s) to copy, but will be one more step, i.e. when the session is switched to select, with or prefix wview all of the session and window, and select switch.

Ref:
Installation Reference: https://www.jianshu.com/p/f7f24b4b2625
Reference: https://www.cnblogs.com/liuguanglin/p/9290345.html

Guess you like

Origin www.cnblogs.com/jessepeng/p/12452169.html