最简单最省事儿的方式上手用tmux

tmux (https://github.com/tmux/tmux/wiki)

快捷方式

纵向切分窗口: ctrl+j+%
横向切分窗口: ctrl+j+"

新建窗口:ctrl+j+n
关闭窗口:ctrl+j+x
重命名窗口:ctrl+j+,
最大化窗口:ctrl+j+z
切换窗口:shift+方向键

切换窗格:ctrl+j+方向键
调整窗格大小:ctrl+j+ctrl+方向键

复制模式:ctrl+j+[

自动化脚本

安装完tmux后,无需任何配置。每次执行这个脚本启动tmux即可。

#!/bin/sh
#
# name     : tmux.sh, make tmux easy
# author   : leapking [email protected]
# license  : GPL
# created  : 2015 May 12
# modified : 2017 Nov 08
#

CMD=$(which tmux) # get tmux path
if [ -z $CMD ]; then
    echo "You need to install tmux."
    exit 1
fi

###
### Check Config ###
if [ ! -f /etc/tmux.conf -a ! -f ~/.tmux.conf ]; then
cat <<-EOF >~/.tmux.conf
# Easy config reload
bind r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded ..."

# Send prefix
set -g prefix C-j
unbind C-b

# Switch windows use Shift+Arrow key
bind -n S-Left  previous-window
bind -n S-Right next-window

# Switch panes use Alt+Arrow key
bind -n M-Left  select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up    select-pane -U
bind -n M-Down  select-pane -D

# While split or create window turn to old path
bind '%' split-window -h -c '#{pane_current_path}'
bind '"' split-window -v -c '#{pane_current_path}'
bind 'c'   new-window    -c '#{pane_current_path}'

# Window index and size
set  -g base-index 1         # start windows numbering at 1
set  -g renumber-windows on  # renumber windows when a window is closed
setw -g pane-base-index 1    # make pane numbering consistent with windows
setw -g automatic-rename on  # rename window to reflect current program
setw -g aggressive-resize on # aggressively resize the chosen window

# Others
#set  -g mouse on            # mouse mode
setw -g mode-keys vi         # start vi mode
set -g history-limit 65535   # num of history recoders
EOF
fi

if [ ! -f ~/.vimrc ]; then
cat <<-EOF >~/.vimrc
colorscheme desert

" vim color
if exists('$TMUX')
    set term=screen-256color
endif

" mouse type
if exists('$ITERM_PROFILE')
    if exists('$TMUX') 
        let &t_SI = "\[3 q"
        let &t_EI = "\[0 q"
    else
        let &t_SI = "\]50;CursorShape=1\x7"
        let &t_EI = "\]50;CursorShape=0\x7"
    endif
end

" for tmux to automatically set paste and nopaste mode at the time pasting (as happens in VIM UI)
function! WrapForTmux(s)
    if !exists('$TMUX')
        return a:s
    endif

    let tmux_start = "\Ptmux;"
    let tmux_end = "\\\"

    return tmux_start . substitute(a:s, "\", "\\", 'g') . tmux_end
endfunction

let &t_SI .= WrapForTmux("\[?2004h")
let &t_EI .= WrapForTmux("\[?2004l")

function! XTermPasteBegin()
    set pastetoggle=[201~
    set paste
    return ""
endfunction

inoremap   [200~ XTermPasteBegin()
EOF
fi
[ x"$1" == xconfig ] && exit 0

###
### Start Tmux ###
SESSION=leap                 # set session name

$CMD has -t $SESSION &>/dev/null
if [ $? != 0 ]; then
    $CMD new-session -s "$SESSION" -d -n "work1"
    $CMD split-window -v "top"

    $CMD new-window -t $SESSION:2 -n "work2"
    $CMD split-window -h

    $CMD new-window -t $SESSION:4 -n "work3"
    $CMD split-window -h

    $CMD new-window -t $SESSION:5 -n "work4"
    $CMD split-window -h

    $CMD select-window -t $SESSION:2
fi

$CMD -2 attach-session -t $SESSION

你可能感兴趣的:(最简单最省事儿的方式上手用tmux)