設定ファイル
tmuxは.tmux.confファイルで詳細にカスタマイズできます。
設定ファイルの場所
デフォルトの設定ファイル:
~/.tmux.conf
基本的な設定方法
オプション設定
# セッションオプション
set-option -g <option> <value>
set -g <option> <value>
# ウィンドウオプション
set-window-option -g <option> <value>
setw -g <option> <value>
よく使う設定
プレフィックスキーの変更
デフォルトのCtrl+bからCtrl+aに変更:
# 現在のプレフィックスをアンバインド
unbind C-b
# 新しいプレフィックスを設定
set-option -g prefix C-a
# Ctrl+a Ctrl+a で送信
bind-key C-a send-prefix
マウス操作の有効化
set-option -g mouse on
ウィンドウの表示番号を1から開始
set-option -g base-index 1
set-window-option -g pane-base-index 1
ウィンドウ名の自動更新を無効化
set-window-option -g automatic-rename off
デフォルトシェル設定
set-option -g default-shell /bin/zsh
カラー設定
# 256色対応
set-option -g default-terminal "screen-256color"
# ターミナルオーバーライド
set-option -sa terminal-overrides ",xterm-256color:RGB"
ステータスバーのカスタマイズ
# ステータスバー位置(top または bottom)
set-option -g status-position top
# ステータスバーの高さ
set-option -g status-style bg=black,fg=white
# 左側の表示
set-option -g status-left " #S "
set-option -g status-left-length 20
# 中央の表示
set-option -g status-justify centre
# 右側の表示
set-option -g status-right " %H:%M:%S "
キーバインドのカスタマイズ
新しいキーバインドを追加
# 設定ファイルの再読み込み
bind-key r source-file ~/.tmux.conf \; display "Configuration Reloaded!"
# ペイン分割のキーを変更
bind-key v split-window -h
bind-key s split-window -v
キーバインドの削除
unbind-key c
実践的な設定例
開発環境向け設定
# ~/.tmux.conf
# プレフィックスキー
set-option -g prefix C-a
unbind C-b
bind C-a send-prefix
# マウス対応
set-option -g mouse on
# ウィンドウ番号を1から開始
set-option -g base-index 1
# キーバインドカスタマイズ
bind v split-window -h -c "#{pane_current_path}"
bind s split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
# ステータスバー
set-option -g status-bg blue
set-option -g status-fg white
set-option -g status-left "[#S] "
set-option -g status-right "%H:%M"
# 設定ファイル再読み込み
bind r source-file ~/.tmux.conf \; display "Config reloaded"
最小限の設定
# ~/.tmux.conf
# プレフィックスをCtrl+aに
set-option -g prefix C-a
unbind C-b
# マウス有効
set-option -g mouse on
# 設定ファイル再読み込み
bind r source-file ~/.tmux.conf
設定ファイルの反映
設定ファイルを編集後、以下のキーバインドで反映:
Ctrl+b :
source-file ~/.tmux.conf
Enter
または設定ファイルに再読み込みキーバインドを追加:
bind r source-file ~/.tmux.conf \; display "Configuration reloaded!"
その後、Ctrl+b rで再読み込みできます。
トラブルシューティング
設定が反映されない
- ファイルがない場合は作成
- 既存セッションは新しい設定を読み込まないため、セッションを再作成
tmux source-file ~/.tmux.confで強制適用
キーバインドが効かない
Ctrl+b ?で現在のキーバインドを確認- 設定ファイルのシンタックスをチェック
より詳しい設定
詳細な設定は man tmux を参照してください:
man tmux
またはtmux公式ドキュメント:https://github.com/tmux/tmux/wiki