LoginSignup
0
0

More than 1 year has passed since last update.

[02] tmux 2.6 で emacs 風のキーバインドにする ... Emacs風キー割り当て

Last updated at Posted at 2021-08-07

はじめに

Linux 上であれば Emacs でシェルを操作したいが、
各種事情により Emacs を導入できない場合の代替手段として tmux 2.6 を使う.

tmux はバージョンが更新されると、過去の設定が動かなくなるので、
私は 2.6 で固定して使っている.

色々と参考にさせてもらった御礼の意味をこめて、次の emacs 操作風の設定を記しておく.
本項では 「tmux 2.6」における Emacs キー操作の $HOME/.tmux.conf を記す.

image.png

環境

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"

事前準備

システムに xclip をインストールしておくこと

参考サイト

タイトル 記事
tmux basic concept https://qiita.com/toripiyo/items/e713779ba596c350ccd8
tmux のキーバインドを vi 風にする http://tegetegekibaru.blogspot.com/2012/08/tmux-vi.html
544 GitHub/dotfiles https://github.com/544/dotfiles/blob/master/.tmux.conf

tmux 2.6 の設定ファイル

$HOME/.tmux.conf

prefix は C-x である

# ======================
# Setting For tmux
# ======================
# プレフィックスキー C-x
unbind C-b
set-option -g prefix C-x

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

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

#全てのベルを無視
set-option -g bell-action none
# ウィンドウ番号基準値
set-option -g base-index 1
# ウィンドウの自動リネームoff
set-window-option -g automatic-rename off
#ウィンドウで動作があるとステータスラインでハイライト
set-window-option -g monitor-activity on

# コピー、選択モードのキーバインドemacs
set -g mode-keys emacs

# 設定ファイル再読み込み r
bind r source-file ~/.tmux.conf \; display-message "Reloaded config !!"

# Sync
bind S setw synchronize-panes on
bind E setw synchronize-panes off

# 直前のウィンドウ t
bind C-t last-window

# デタッチ d
bind d detach

# タイトル変更 A
bind A command-prompt "rename-window %%"

# ウィンドウ選択画面
bind b choose-window

# 新ウィンドウ作成
bind 5 new-window

# 分割していたペインそれぞれをWindowに
# bind 0 break-pane

# ペイン終了
bind k kill-pane

# ウィンドウ終了
bind C-c kill-window

# ペイン番号表示
#bind i display-panes

# ペインの縦分割
bind 2 split-window -v
# ペインの横分割
bind 4 split-window -h

# resize panes like vim
# feel free to change the "1" to however many lines you want to resize by, only
# one at a time can be slow
bind < resize-pane -L 1
bind > resize-pane -R 1
bind - resize-pane -D 1
bind + resize-pane -U 1

# history size
set-option -g history-limit 100000
set-option -g mouse on

bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M

#bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"

# ステータスラインの設定 {{{
# powerline setting
set-option -g status on
set -g status-interval 1
# window list alignment
set-option -g status-justify "left"
set-option -g status-left-length 150
set-option -g status-right-length 150
set-option -g status-left "#(~/.tmux/tmux-powerline/powerline.sh left)"
set-option -g status-right "#(~/.tmux/tmux-powerline/powerline.sh right)"
# # }}}

# window-status を中央揃えで配置する
set-option -g status-justify "centre"
# # status line の背景色を指定する。
set-option -g status-fg white
set-option -g status-bg black
# 現在のウィンドウの色
set-window-option -g window-status-current-fg   white
set-window-option -g window-status-current-bg   blue

# Copy Mode Start
# To copy:
#ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
# tmux 2.0 の場合
#ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
# bind-key -n -t emacs-copy M-w copy-pipe "xclip -i -sel p -f | xclip -i -sel c "
# bind-key -n -t emacs-copy C-w copy-pipe "xclip -i -sel p -f | xclip -i -sel c "

#ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
# tmux 2.6 の場合
#ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
bind-key -n -T copy-mode M-w send-keys -X copy-pipe-and-cancel "xclip -i -sel p -f | xclip -i -sel c "
bind-key -n -T copy-mode C-w send-keys -X copy-pipe-and-cancel "xclip -i -sel p -f | xclip -i -sel c "

# To paste:
bind-key -n C-y run "xclip -o | tmux load-buffer - ; tmux paste-buffer"

set-option -g status-left '#[fg=cyan,bg=#303030]#{?client_prefix,#[reverse],} #H[#S] #[default]'

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