tmux始め方(ubuntu18.04)

screenを使っていたが原因不明のフリーズが頻繁に起きてtmuxに乗り換えました。

  1. tmuxをインストール。
  2. homeディレクトリに.tmux.confをtouchコマンドで作成。
  3. https://qiita.com/succi0303/items/cb396704493476373edf←ここに書かれた .tmux.confを2.で作成した.tmux.confにコピペする。
  4. tmuxを起動させる。新しくターミナルを立ち上げてtmuxと入力する。
  5. 3.の設定変更を反映させるために tmux source-file ~/.tmux.conf と入力する。
  6. これで設定完了に思ってしまいますが tmux kill-server でtmuxを一度オフにしてから tmuxでもう一度起動させると [exited] と表示されて起動できません。https://qiita.com/takc923/items/018733112963b69b408b←こちらを参考にしてset-option -g default-command "" と書き換えて、tmux source-file ~/.tmux.conf で変更を反映させると無事起動します。
  7. ここまでの設定で十分使えるらしいですが私は使いにくかったので、
    ## viのキーバインドを使用する
    setw -g mode-keys vi
    ## クリップボード共有を有効にする
    set-option -g default-command "reattach-to-user-namespace -l zsh"
    ## コピーモードの操作をvi風に設定する
    bind-key -T copy-mode-vi v send-keys -X begin-selection
    bind-key -T copy-mode-vi y send-keys copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
    unbind -T copy-mode-vi Enter
    bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

↑の部分をhttps://qiita.com/purutane/items/1d1dc4818013bbbaead4←こちらを参考にして書き換えました。
ubuntuにはデフォルトでxselがないのでxselをインストールしてからお試しください。

sudo apt install xsel


完全版

# fixキーをC-aに変更する
set -g prefix C-a

# C-bのキーバインドを解除する
unbind C-b

# キーストロークのディレイを減らす
set -sg escape-time 1

# ウィンドウのインデックスを1から始める
set -g base-index 1

# ペインのインデックスを1から始める
setw -g pane-base-index 1

# 設定ファイルをリロードする
bind r source-file ~/.tmux.conf \; display "Reloaded!"

# C-a*2でtmux内のプログラムにC-aを送る
bind C-a send-prefix

# | でペインを縦に分割する
bind | split-window -h

# - でペインを横に分割する
bind - split-window -v

# Vimのキーバインドでペインを移動する
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+

# Vimのキーバインドでペインをリサイズする
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# マウス操作を有効にする
setw -g mouse on

# 256色端末を使用する
set -g default-terminal "screen-256color"

# ステータスバーの色を設定する
set -g status-fg white
set -g status-bg black

# ウィンドウリストの色を設定する
setw -g window-status-fg cyan
setw -g window-status-bg default
setw -g window-status-attr dim
# アクティブなウィンドウを目立たせる
setw -g window-status-current-fg white
setw -g window-status-current-bg red
setw -g window-status-current-attr bright

# ペインボーダーの色を設定する
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

# コマンドラインの色を設定する
set -g message-fg white
set -g message-bg black
set -g message-attr bright

# ステータスバーを設定する
## 左パネルを設定する
set -g status-left-length 40
set -g status-left "#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P"
## 右パネルを設定する
set -g status-right "#[fg=cyan][%Y-%m-%d(%a) %H:%M]"
## リフレッシュの間隔を設定する(デフォルト 15秒)
set -g status-interval 60
## ウィンドウリストの位置を中心寄せにする
set -g status-justify centre
## ヴィジュアルノーティフィケーションを有効にする
setw -g monitor-activity on
set -g visual-activity on
## ステータスバーを上部に表示する
set -g status-position top

# コピーモードを設定する
set-window-option -g mode-keys vi

bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xsel -bi"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xsel -bi"