LoginSignup
14
15

More than 5 years have passed since last update.

tmux+iTerm2設定

Last updated at Posted at 2014-06-02

表題の組み合わせでターミナルの環境を作りました。
個人的にハマったところと解消法法、および便利だと思う設定を記載します。

.tmux.conf

prefixをデフォルトから(C-b)を変えたい

prefixのデフォルトのC-bはEmacsのキーバインドとぶつかるのでC-tに変更。また<prefix> rで.tmux.confをリロードする。

unbind C-b
set -g prefix C-t
#私は設定していませんが、prefixを連続で押すとprefixのキーを押したことにする設定の方が多いです。
#bind C-t send-prefix

unbind r
bind r source-file ~/.tmux.conf \; display-message "~/.tmux.conf is reloaded"

使いやすいキーバインドに変える

よく使う操作は押しやすいキーバインドを設定した方がよいです。.tmux.confを編集し<prefix> rを押すだけで反映されます。

bind 0 kill-pane
bind 1 kill-pane -a
bind 2 split-window -v
bind 3 split-window -h
bind t new-window
bind w kill-window
bind l next-window
bind h previous-window
bind a kill-window -a
bind q kill-session

prefixを押さずに操作したい

bind -nでprefixなしのキーバインドを設定できます。

bind -n C-o  select-pane -t :.+

prefixを押さずに操作したい(その2)

bind -rで設定した操作は二度目以降prefixを省略できます。例えばC-t C-l C-lで二つ右のwindowに移動できます。

bind -r C-o select-pane -t :.+
bind -r C-l next-window
bind -r C-h previous-window
bind -r C-t new-window
bind -r C-w kill-window

#次の操作の受付時間はデフォルト0.5秒ですが変更できます。下記で1秒になります。
set -g repeat-time 1000

ステータスバーをカスタマイズしたい

  • ステータスバーを上に表示
  • 色をブラウザのタブ風の灰色+白(選択中のタブ)に変更しています。
  • windowの間に|を挟むと若干見やすい気がします。
  • windowのindexを指定して移動することがないので表示させていません。
set -g status-position top
set -g status-fg black
set -g status-bg colour246
set -g window-status-current-fg black
set -g window-status-current-bg colour255
set -g window-status-format " #W |"
set -g window-status-current-format " #W |"
set -g status-left ""
set -g status-right "#[fg=black][#S]"

マウスを使いたい

下記設定でマウスを使ったスクロールと範囲選択ができるようになります。

set -g mode-mouse on
set -g mouse-utf8 on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on

windowの履歴の行数を増やす

set -g history-limit 10000

Escを押したときすぐ反応させる

set -s escape-time 0

iTerm2の設定

指定した色が表示されないとき

iTerm2上でtmuxのステータスバーなどを256色で表示するため環境変数TERMを変更します。
iTerm2のPreferences -> Profiles -> Terminal -> Report Terminal Typexterm-256colorに変更。

$ echo ${TERM}
xterm # 変更前
xterm-256color # 変更後

コピー&ペースト

上記の設定だと範囲選択とCmd-cによるコピーができませんが、Optionを押しながら範囲選択するとコピーできます。

エイリアス

よく使うtmuxコマンドにはaliasを設定すると便利です。

alias a='alias'
a t="tmux"
a tl="t ls"
function ta() {
  if [ -z $1 ]; then
    t a
  else
    t a -t $1
  fi
}
function tk() {
  if [ -z $1 ]; then
    t kill-session
  else
    t kill-session -t $1
  fi
}
14
15
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
14
15