awesomewm-vim-tmux-navigator/README.md

98 lines
3.8 KiB
Markdown
Raw Normal View History

2020-03-22 23:19:52 +01:00
AwesomeWM - Vim - Tmux Navigator
==================
2020-06-26 18:35:48 +02:00
<p align="center">
<img src="https://s7.gifyu.com/images/magic2c10caab0952e59d4.gif">
</p>
2021-03-29 16:17:59 +02:00
`awesomewm-vim-tmux-navigator` lets you navigate seamlessly between system windows, vim splits and tmux panes by only using your awesomewm navigation keybindings.
Every vim split and tmux pane is treated like a regular system window, allowing you to forget your vim/tmux specific navigation hotkeys.
It also works in complex scenarios like embedded vim splits inside tmux panes.
2021-03-29 16:17:59 +02:00
This plugin adds another layer to christoomey's plugin [vim-tmux-navigator](https://github.com/christoomey/vim-tmux-navigator), which does most of the heavy lifting.
2020-06-26 18:35:48 +02:00
How does it work
------------
The plugin sends the correct keypresses based on the focused appplication.
In order to differentitate between (n)vim and tmux clients, the title of your terminal is changed.
2021-02-18 20:52:05 +01:00
Therefore your shell/terminal stack has to support dynamic titles (see Troubleshooting section).
2020-03-22 23:19:52 +01:00
Installation
------------
### AwesomeWM
Clone the repo.
```
2020-06-26 18:35:48 +02:00
git clone https://github.com/intrntbrn/awesomewm-vim-tmux-navigator ~/.config/awesome/awesomewm-vim-tmux-navigator
2020-03-22 23:19:52 +01:00
```
It's not recommended to change the path since it's hardcoded in other configuration files.
2020-03-22 23:19:52 +01:00
Add your preferred navigation (focus) keybinds to `rc.lua` (e.g. <kbd>Mod4</kbd>+<kbd>arrows</kbd> or <kbd>Mod4</kbd>+<kbd>hjkl</kbd>)
2020-03-22 23:19:52 +01:00
```
require("awesomewm-vim-tmux-navigator") {
up = {"Up", "k"},
down = {"Down", "j"},
left = {"Left", "h"},
right = {"Right", "l"},
mod = "Mod4",
mod_keysym = "Super_L"
}
2020-03-22 23:19:52 +01:00
```
Please verify that `mod` and `mod_keysym` matches your actual awesomewm modifier key by using the terminal application `xev`.
For instance you might be using the right windows/super key and have to specify "Super_R" as your `mod_keysym`, or "Mod1" and "Alt_L" if you prefer to use the alt key.
2021-03-29 16:17:59 +02:00
Don't forget to remove your previously used navigation keybinds (or other conflicting keybinds) in `rc.lua`.
2020-03-22 23:19:52 +01:00
### Vim
```vim
Plug 'intrntbrn/awesomewm-vim-tmux-navigator'
```
Remove similar plugins (like `christoomey/vim-tmux-navigator`).
**Options:**
`let g:tmux_navigator_insert_mode = 1` to enable navigator keybinds in insert mode
2020-03-22 23:19:52 +01:00
### Tmux
2021-03-29 16:17:59 +02:00
Add the following to your `tmux.conf` at the very bottom.
2020-03-22 23:19:52 +01:00
```tmux
# Set Terminal titles where possible
set-option -g set-titles on
set-option -g set-titles-string '#S: #W - TMUX'
# Smart pane switching with awareness of vim splits and system windows
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind -n C-Left if-shell "$is_vim" "send-keys C-h" "run-shell 'sh ~/.config/awesome/awesomewm-vim-tmux-navigator/tmux_focus.sh left'"
bind -n C-Down if-shell "$is_vim" "send-keys C-j" "run-shell 'sh ~/.config/awesome/awesomewm-vim-tmux-navigator/tmux_focus.sh down'"
bind -n C-Up if-shell "$is_vim" "send-keys C-k" "run-shell 'sh ~/.config/awesome/awesomewm-vim-tmux-navigator/tmux_focus.sh up'"
bind -n C-Right if-shell "$is_vim" "send-keys C-l" "run-shell 'sh ~/.config/awesome/awesomewm-vim-tmux-navigator/tmux_focus.sh right'"
```
Troubleshooting
---------------
After a correct installation the title of a tmux session should end with "- TMUX" and "- VIM" or "- NVIM" for vim or nvim sessions respectively.
2021-02-18 21:06:36 +01:00
Check the title of the terminal client in your wm tasklist or by using `xprop` (title is property `WM_NAME`).
2021-02-18 20:52:05 +01:00
2021-03-18 21:05:08 +01:00
In case your title does not change, your terminal and/or shell do not support dynamic titles or are not configured.
2021-02-18 20:52:05 +01:00
2021-03-18 21:05:08 +01:00
Try minimal configurations provided for `zsh` or `bash`:
2021-02-18 20:52:05 +01:00
```
echo "source ~/.config/awesome/awesomewm-vim-tmux-navigator/dynamictitles.zsh" >> ~/.zshrc
```
or
```
echo "source ~/.config/awesome/awesomewm-vim-tmux-navigator/dynamictitles.bash" >> ~/.bashrc
```
2021-03-29 16:17:59 +02:00
I recommend to use `alacritty` with `zsh`.