0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

tmux入門 ー ペイン分割とセッション管理でターミナル操作を効率化する

0
Last updated at Posted at 2026-02-27

tmux導入で、ペイン分割で複数を一画面に並べ、セッション管理でターミナルを閉じても作業状態を保持できます。Claude CodeのAgent Teamsがsplit-paneモードでtmuxを利用するなど、AIエージェント周辺でもtmuxが前提になりつつあります。

インストールと起動

# macOS
brew install tmux

# Ubuntu/Debian
sudo apt install tmux

セッションを名前付きで起動します。

tmux new -s main

画面下部にステータスバーが出ればtmuxの中に入っています。

3層構造

tmuxはセッション > ウィンドウ > ペインの3層構成です。

  • セッション:最上位の単位。デタッチ / アタッチで中断・再開
  • ウィンドウ:セッション内のタブ
  • ペイン:ウィンドウ内の分割領域

まずはセッション1つ + ペイン分割で十分です。

基本キーバインド

prefixキー(デフォルトCtrl+b)を押して離してから操作キーを押します。同時押しではないことに注意です。

操作 キー
水平分割(上下) prefix + "
垂直分割(左右) prefix + %
フォーカス移動 prefix + 矢印キー
ペインを閉じる prefix + x
ズーム切替 prefix + z
デタッチ prefix + d

.tmux.conf でカスタマイズ

~/.tmux.confに以下を書くことでカスタマイズ可能です。

~/.tmux.conf
# prefix を Ctrl+a に変更
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# マウス操作を有効化
set -g mouse on

# ペイン分割を直感的なキーに変更
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

設定を反映するにはtmux内でtmux source-file ~/.tmux.confを実行します。

セッションのデタッチと再接続

prefix + d でデタッチすると、セッション内のプロセスはバックグラウンドで動き続けます。

# セッション一覧
tmux ls

# 再接続
tmux attach -t main

SSH接続が切れてもセッションは残るため、再接続するだけで作業を再開できます。

セッションはtmuxサーバーのプロセスが生きている間だけ保持されます。マシン再起動で消えるため、再起動をまたぐには tmux-resurrect が必要です。

次のステップとしては、tmux-resurrectやtpmを導入するとさらに便利になります。
tmuxの操作に慣れてきたらtmux公式 Wikiも参照してください。

この記事の詳細版は Zenn で公開しています: tmux入門 インストールからペイン分割・セッション管理まで

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?