2
2

More than 1 year has passed since last update.

[備忘録]Tmux + Neovimで快適なターミナル環境を構築する

Posted at

本投稿内容はこちらのYouTube動画の内容に沿って行いました。

構築後のターミナル使用のイメージ

スクリーンショット 2022-12-02 19.05.02.png
ターミナル画面を複数のセッション、ウィンドウ、ペインに分割して利用することができ、それぞれの移動もスムーズな点が魅了的です。

Tmuxとは

ターミナルマルチプレクサ(Terminal Multiplexer) の略です。
Linux 系のターミナル画面を複数のセッション、ウィンドウ、ペインに分割して利用することができます。

とほほのtmux入門を参照)

実施環境

mac OS Big Sur
バージョン 11.5.1

HomebrewでTmuxをインストール

brew install tmux

tpm (tmux plugin manager)をインストールする

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

~/.tmux.confファイルを作成する

touch ~/.tmux.conf

~/.tmux.confファイルを以下の内容を記載する

set -g default-terminal "screen-256color"

set -g prefix C-a
unbind C-b
bind-key C-a send-prefix

unbind %
bind | split-window -h

unbind '"'
bind - split-window -v

unbind r
bind r source-file ~/.tmux.conf

bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5

bind -r m resize-pane -Z

set -g mouse on

set-window-option -g mode-keys vi

bind-key -T copy-mode-vi 'v' send -X begin-selection # start selecting text with "v"
bind-key -T copy-mode-vi 'y' send -X copy-selection # copy text with "y"

unbind -T copy-mode-vi MouseDragEnd1Pane # don't exit copy mode when dragging with mouse

# tpm plugin
set -g @plugin 'tmux-plugins/tpm'

# list of tmux plugins
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'jimeh/tmux-themepack'
set -g @plugin 'tmux-plugins/tmux-resurrect' # persist tmux sessions after computer restart

カスタムポイント

Prefixを"Ctrl-a"に変更し、入力負荷を軽減
set -g prefix C-a
unbind C-b
bind-key C-a send-prefix
ウィンドウ分割のキーバインドを直感的なものに変更
unbind %
bind | split-window -h

unbind '"'
bind - split-window -v
プラグインを導入し、NeovimとTmuxウィンドウ・ペインの移動を同一コマンドシームレスに実行可能に

(※Neovim側にも同じプラグインを導入する必要あり)

set -g @plugin 'christoomey/vim-tmux-navigator'

以上で構築は完了です!

2
2
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
2
2