Skip to content

Instantly share code, notes, and snippets.

@hgwr
Last active December 31, 2020 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgwr/408e8c07d359c612222651fbe9fee00f to your computer and use it in GitHub Desktop.
Save hgwr/408e8c07d359c612222651fbe9fee00f to your computer and use it in GitHub Desktop.
.tmux.conf
# tmux cheat sheet
#
# 新規セッション開始: tmux
# 名前をつけて新規セッション開始: tmux new -s <セッション名>
# セッションの一覧表示: tmux ls
# 接続クライアントの一覧表示: tmux lsc
# セッションを再開 ※-t <対象セッション名>でセッション名の指定も可能: tmux a
# セッションを終了 ※-t <対象セッション名>でセッション名の指定も可能: tmux kill-session
# tmux全体を終了: tmux kill-server
# その他コマンドを実行: tmux [command [flags]]
#
# tmux 起動後のショートカット
#
# ? キーバインド一覧
# : コマンドプロンプト
# s セッションの一覧選択
# d セッションから離脱(デタッチ)
# $ セッションの名前変更
#
# c 新規ウインドウ作成
# w ウインドウの一覧選択
# 0-9 指定番号のウインドウへ移動
# & ウインドウの破棄
# n 次のウインドウへ移動
# p 前のウインドウへ移動
# l 以前のウインドウへ移動
# C-t 以前のウインドウへ移動 (screen 互換)
# ' 入力番号のウインドウへ移動
# . 入力番号にウインドウ番号を変更
# , ウインドウの名前変更
# f ウインドウの検索
#
# J Pane と Window の移動
# S Pane と Window の移動
# B Pane の Window 化
# T Window の移動
#
# E キー入力を全てのpaneで同期する
# e キー入力を全てのpaneで同期終了
#
# % 左右にペイン分割
# " 上下にペイン分割
# q ペイン番号を表示
# カーソル 指定方向のペインへ移動 ※連続押しでプレフィックス継続
# Ctrl-カーソル ペインのサイズを変更 ※連続押しでプレフィックス継続
# ! ペインを解除してウインドウ化
# x ペインの破棄
# o ペインを順に移動
# ; 以前のペインへ移動
# z 現在のペインを最大化/復帰
# スペース レイアウトを変更
# Alt-1-5 レイウトを変更
# { ペインの入れ替え(前方向)
# } ペインの入れ替え(後方向)
# ctrl+o ペインの入れ替え(全体)
# t ペインに時計を表示
#
# [ コピーモードの開始(カーソルキーで自由に移動)
# スペース コピー開始位置決定(viモード)
# エンター コピー終了位置決定(viモード)
# ] コピーした内容を貼り付け
#
# Ctrl+t :set-window-option synchronize-panes on 全 pane に同じコマンドを送る
# 現在の tmux バージョンを環境変数に保存: あとの条件分岐で使用する。 https://stackoverflow.com/a/40902312
run-shell 'tmux setenv -g TMUX_VERSION $(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
# prefixをscreenと同じに
unbind C-b
set -g prefix C-t
bind C-t send-prefix
# 256色端末を使用する
set -g default-terminal "xterm-256color"
# viのキーバインドを使用する
setw -g mode-keys vi
# バックスクロール行数を増やす
set -g history-limit 10000
# 実行されているコマンド名をウィンドウ名に
setw -g automatic-rename on
# マウスでペインを選択可に
if-shell -b '[ "$(echo "$TMUX_VERSION < 2.1" | bc)" = 1 ]' " \
set -g mouse-select-pane off; set -g mode-mouse off; \
set -g mouse-resize-pane off; set -g mouse-select-window off; \
set -g message-fg red; \
set -g message-bg black; \
set -g message-attr bright; \
set -g window-status-bg default; \
set -g window-status-fg default; \
set -g window-status-current-attr bold; \
set -g window-status-current-bg cyan; \
set -g window-status-current-fg default; \
set -g window-status-bell-fg red; \
set -g window-status-bell-bg black; \
set -g window-status-activity-fg white; \
set -g window-status-activity-bg black"
if-shell -b '[ "$(echo "$TMUX_VERSION >= 2.1" | bc)" = 1 ]' \
"set -g mouse off"
# ウィンドウ番号を0から始める
set -g base-index 0
# ターミナル(iTerm2等)のタイトルを設定
set -g set-titles on
# utf-8
if-shell -b '[ "$(echo "$TMUX_VERSION < 2.2" | bc)" = 1 ]' \
"set -g utf8 on; set -g status-utf8 on; set -g mouse-utf8 on"
# ステータスバー
set -g status-interval 5
set -g status-bg black
set -g status-bg white
# Ctrlを押しっぱなしでもよいように
bind C-a last-window
bind C-n next-window
bind C-p previous-window
bind C-l select-pane -t :.+
bind C-t last-window
bind C-c new-window
# session with PWD
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
# key bind (paneの移動)
# Shift + カーソルキーで移動
bind -n S-left select-pane -L
bind -n S-down select-pane -D
bind -n S-up select-pane -U
bind -n S-right select-pane -R
# set-option -g set-titles-string "@#(echo $SSH_CONNECTION | cut -d ' ' -f3)"
# 再読み込みをキーバインドしておく
bind R source-file ~/.tmux.conf \; display-message "Reload Config!!"
# Pane と Window の移動、 Pane の Window 化
bind-key J command-prompt -p "join pane from:" "join-pane -s '%%'"
bind-key S command-prompt -p "send pane to:" "join-pane -t '%%'"
bind-key B break-pane
bind-key T command-prompt -p "swap window to:" "swap-window -t '%%'"
# キー入力を全てのpaneで同期する・同期終了
bind E setw synchronize-panes on
bind e setw synchronize-panes off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment