0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

いざ tmux

Posted at

はじめに

これまでなかなかCLI環境に慣れていなかったので
一年発起してCLI環境で暮らすことにしました。

今回は、tmuxに入門しようと思います。

dotfiles

tmuxとは?

tmuxの説明は
tmuxを必要最低限で入門して使うがとてもわかり易いです。
こちらを参考にしてみてください><

.tmux.conf

.tmux.confはtmuxの設定ファイルです。
~/.tmux.confに存在します。

# shell
set-option -g default-shell /usr/local/bin/fish

# color
set-option -g default-terminal screen-256color
set -g terminal-overrides 'xterm:colors=256'

# display
setw -g automatic-rename on
set -g renumber-windows on
set -g set-titles on

# activity
set -g monitor-activity on
set -g visual-activity off

# naviation
bind C-c new-session

# active window
# setw -g window-status-activity-style bg="colour16","underscore",fg="colour45"
setw -g window-status-current-style bright
setw -g window-status-style dim

# index
set -g base-index 1
set-window-option -g pane-base-index 1

# active pain
set -g pane-border-style fg="colour236"

# reload
bind r source-file ~/.tmux.conf \; display-message "Reload Config!!"

# prefix key
set -g prefix C-a
unbind C-b

# history
set-option -g history-limit 10000


# vim pain
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
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

# pain split 
bind | split-window -h
bind - split-window -v

# mouse
set-option -g mouse on
# set -g mouse-select-pane on
# set -g mouse-resize-pane on
# set -g mouse-select-window on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"

# vim copy
setw -g mode-keys vi
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi V send -X select-line
bind -T copy-mode-vi C-v send -X rectangle-toggle
bind -T copy-mode-vi y send -X copy-selection
bind -T copy-mode-vi Y send -X copy-line
bind-key C-p paste-buffer

# powerline status
set-option -g status on
set-option -g status-interval 1
set-option -g status-justify "centre"
set-option -g status-left-length 300
set-option -g status-right-length 90
set-option -g status-left "#(~/dotfiles/.tmux/tmux-powerline/powerline.sh left)"
set-option -g status-right "#(~/dotfiles/.tmux/tmux-powerline/powerline.sh right)"

# F
# I index for current window
# W name for current window
set-window-option -g window-status-current-format "#[fg=colour235, bg=colour235]⮀#[fg=colour255, bg=colour102] #F #I  #W #[fg=colour102, bg=colour235]⮀"
set -g status-bg colour239


bind C-[ run '~/path/to/tmux-powerline/mute_powerline.sh left'
bind C-] run '~/path/to/tmux-powerline/mute_powerline.sh right'

# plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-open'
set -g @plugin 'tmux-plugins/tmux-resurrect'


run -b '~/.tmux/plugins/tpm/tpm'

ドキュメントや色々なサイトを参考にさせていただきました。
特に設定が必要なのが
powerline statusのtmux-powerlinetmux-pluginsです。

tmux-powerlineは、下部にpowerlineを表示し
tmux-pluginはtmuxでプラグインを使用するために必要です。

スクリーンショット 2020-04-30 22.34.06.png

VimもPowerlineを使っているため画面がffffぐちゃぐちゃなので、あとで改修したいです・・・><

tmux(外)の操作

  • tmuxでセッションを新規作成する
tmux

もしすでにtmuxに入っているときは

prefix + cで新規セッション

  • tmuxでセッション一覧を表示する
tmux ls
  • tmuxでセッションを再開する
tmux a -t セッション名
  • tmuxでセッションを終了する
tmux kill-session -t セッション名
  • すべてのセッションを殺す
tmux ls | grep : | cut -d. -f1 | awk '{print substr($1, 0, length($1)-1)}' | xargs kill

tmux(内)の操作

全体

コマンド 機能
prefix + ? コマンド一覧の表示
prefix + w セッション+window 一覧
prefix + s セッション一覧
prefix + : コマンドラインモード
prefix + [ コピーモード開始
v コピーモードでコピー開始位置決定
y ヤンク
prefix + (Ctrl + p) コピー内容の貼り付け

セッション

コマンド 機能
prefix + :, :new コマンドラインモードで:newをして新しいセッションを作る
prefix + d 今のセッションから一時抜ける
ctrl + d 今のセッションの削除
prefix + $ セッション名の変更

ウィンドウ

コマンド 機能
prefix + c 新規ウィンドウ
prefix + & 今のウィンドウを消去する
prefix + n 次のウィンドウへ移動する
prefix + p 前のウィンドウへ移動する
prefix + 1~9 番号のウィンドウに移動
prefix + , ウィンドウ名の変更
prefix + f ウィンドウの検索

ペイン

コマンド 機能
prefix + x 今のペインの削除
prefix + | ペインを左右に分割する
prefix + - ペインを上下に分割する
prefix + hjkl ペインを移動する
prefix + HJKL ペインのサイズを変える
prefix + space ペインをいい感じに調整する
prefix + (Ctrl + o) ペインを回転させる
prefix + { 上方向にペインを入れ替える
prefix + } 下方向にペインを入れ替える
prefix + z 今のペインの最大化 と 復帰
prefix + q ペイン番号の表示
prefix + ! 今のペインをウィンドウ化
prefix + :setw synchronize-panes すべてのペインに同時入力する(トグル式)

その他

コマンド 機能
prefix + (Ctrl+s) すべての状態を保存する (resurrent)
prefix + (Ctrl+r) | すべての状態を復元する (resurrent)
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?