LoginSignup
39
40

More than 5 years have passed since last update.

【Vim × tmux】Pane(tmux) - Window(Vim)の移動をシームレスに

Last updated at Posted at 2014-09-29

C-h が殺されるのがつらすぎてこの設定はつかわなくなった
現在の設定 :point_right: https://qiita.com/izumin5210/items/d2e352de1e541ff97079


Vim × tmuxの画面移動

tmuxでpane分割してVimを開いて作業しているとき,Vim内でもウィンドウ分割をすると画面内の移動が大変ややこしいことになる.

vim-tmux.png

面倒なのでVimとかtmuxとか気にせずに 同じキーバインドで 画面の移動をしたい.

Vim Tmux Navigator

Vim Tmux Navigatorを使うと捗る.
Vim・tmuxを気にせず以下の様なキーバインドで画面を移動できる.

  • C-h: 左に移動
  • C-j: 下に移動
  • C-k: 上に移動
  • C-l: 右に移動

導入

Vim側

NeoBundleだとこんな感じ.

.vimrc
NeoBundle 'christoomey/vim-tmux-navigator'

tmux側

.tmux.confに以下を追記する.快適!٩(๑❛ᴗ❛๑)۶

.tmux.conf
# Smart pane switching with awareness of vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)g?(view|n?vim?)(diff)?$' && tmux send-keys 'C-\\') || tmux select-pane -l"

設定

公式のrepositoryを参照.
キーバインドを変更したり色々できる.

参考文献

39
40
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
39
40