-
-
Save jonathanccalixto/f1177d7eeebbcd141a69 to your computer and use it in GitHub Desktop.
Revisions
-
mislav revised this gist
Jul 21, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ curl -fsSL https://gist.github.com/mislav/5189704/raw/tmux.conf \ >> ~/.tmux.conf curl -fsSL https://raw.github.com/mislav/dotfiles/1500cd2/bin/tmux-vim-select-pane \ -o /usr/local/bin/tmux-vim-select-pane chmod +x /usr/local/bin/tmux-vim-select-pane -
mislav revised this gist
Jun 25, 2013 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,4 +3,7 @@ bind -n C-k run-shell 'tmux-vim-select-pane -U' bind -n C-j run-shell 'tmux-vim-select-pane -D' bind -n C-h run-shell 'tmux-vim-select-pane -L' bind -n C-l run-shell 'tmux-vim-select-pane -R' bind -n "C-\\" run-shell 'tmux-vim-select-pane -l' # Bring back clear screen under tmux prefix bind C-l send-keys 'C-l' -
mislav revised this gist
Jun 22, 2013 . 2 changed files with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,11 +21,11 @@ The solution has 3 parts: ## Installation * check `tmux -V` that you have **v1.8** * get the [vim-tmux-navigator](https://github.com/christoomey/vim-tmux-navigator) plugin * additional `~/.tmux.conf` config & `tmux-vim-select-pane` script: ```sh curl -fsSL https://gist.github.com/mislav/5189704/raw/install.sh | bash -e This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ curl -fsSL https://gist.github.com/mislav/5189704/raw/tmux.conf \ >> ~/.tmux.conf curl -fsSL https://raw.github.com/mislav/dotfiles/cd845d96/bin/tmux-vim-select-pane \ -o /usr/local/bin/tmux-vim-select-pane chmod +x /usr/local/bin/tmux-vim-select-pane -
mislav revised this gist
Jun 22, 2013 . 2 changed files with 11 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,12 @@ The solution has 3 parts: ## Installation Requirements: * **tmux v1.8** (check with `tmux -V`) * the [vim-tmux-navigator](https://github.com/christoomey/vim-tmux-navigator) plugin * additional `~/.tmux.conf` config and `tmux-vim-select-pane` script: ```sh curl -fsSL https://gist.github.com/mislav/5189704/raw/install.sh | bash -e ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,7 @@ curl -fsSL https://gist.github.com/mislav/5189704/raw/tmux.conf \ >> ~/.tmux.conf curl -fsSL https://raw.github.com/mislav/dotfiles/ea86d75e/bin/tmux-vim-select-pane \ -o /usr/local/bin/tmux-vim-select-pane chmod +x /usr/local/bin/tmux-vim-select-pane -
mislav revised this gist
Apr 7, 2013 . 2 changed files with 2 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ curl -fsSL https://gist.github.com/mislav/5189704/raw/tmux.conf \ >> ~/.tmux.conf curl -fsSL https://github.com/mislav/dotfiles/blob/ea86d75e/bin/tmux-vim-select-pane \ -o /usr/local/bin/tmux-vim-select-pane chmod +x /usr/local/bin/tmux-vim-select-pane curl -fsSL https://github.com/mislav/vimfiles/blob/41bfa10b/plugin/tmux_navigator.vim \ -o ~/.vim/plugin/tmux_navigator.vim --create-dirs This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ -
mislav revised this gist
Apr 1, 2013 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,4 +3,4 @@ bind -n C-k run-shell 'tmux-vim-select-pane -U' bind -n C-j run-shell 'tmux-vim-select-pane -D' bind -n C-h run-shell 'tmux-vim-select-pane -L' bind -n C-l run-shell 'tmux-vim-select-pane -R' bind -n "C-\\" run-shell 'tmux-vim-select-pane -l' -
mislav revised this gist
Apr 1, 2013 . 2 changed files with 11 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ curl -fsSL https://gist.github.com/mislav/5189704/raw/tmux.conf \ >> ~/.tmux.conf curl -fsSL https://gist.github.com/mislav/5189704/raw/tmux-vim-select-pane.sh \ -o /usr/local/bin/tmux-vim-select-pane chmod +x /usr/local/bin/tmux-vim-select-pane curl -fsSL https://github.com/mislav/vimfiles/blob/33223b73/plugin/tmux_navigator.vim \ -o ~/.vim/plugin/tmux_navigator.vim --create-dirs This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,14 +22,5 @@ The solution has 3 parts: ## Installation ```sh curl -fsSL https://gist.github.com/mislav/5189704/raw/install.sh | bash -e ``` -
mislav revised this gist
Apr 1, 2013 . 2 changed files with 16 additions and 31 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,4 +17,19 @@ The solution has 3 parts: 1. In `~/.tmux.conf`, I bind the keys I want to execute a custom `tmux-vim-select-pane` command; 2. `tmux-vim-select-pane` checks if the foreground process in the current tmux pane is Vim, then forwards the original keystroke to the vim process. Otherwise it simply switches tmux panes. 3. In Vim, I set bindings for the same keystrokes to a custom function. The function tries to switch windows in the given direction. If the window didn't change, that means there are no more windows in the given direction inside vim, and it forwards the pane switching command to tmux by shelling out to `tmux select-pane`. ## Installation ```sh curl -s https://gist.github.com/mislav/5189704/raw/tmux.conf \ >> ~/.tmux.conf curl -L https://gist.github.com/mislav/5189704/raw/tmux-vim-select-pane.sh \ -o /usr/local/bin/tmux-vim-select-pane chmod +x /usr/local/bin/tmux-vim-select-pane curl -L https://github.com/mislav/vimfiles/blob/33223b73/plugin/tmux_navigator.vim \ -o ~/.vim/plugin/tmux_navigator.vim --create-dirs ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +0,0 @@ -
mislav revised this gist
Mar 19, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ set -e active_tty="$(tmux list-panes -F '#{pane_active}#{pane_tty}' | grep '^1')" # checks if there's a foreground Vim process in attached to that tty if ps c -o 'state=,command=' -t "${active_tty#1}" | grep '+' | grep -iE '\bvim?\b' >/dev/null ; then direction="$(echo "${1#-}" | tr 'lLDUR' '\\hjkl')" # forward the keystroke to Vim tmux send-keys C-$direction -
mislav revised this gist
Mar 19, 2013 . 2 changed files with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,10 +8,10 @@ set -e active_tty="$(tmux list-panes -F '#{pane_active}#{pane_tty}' | grep '^1')" # checks if there's a foreground Vim process in attached to that tty if ps -t "${active_tty#1}" c -o 'state=,command=' | grep '+' | grep -iE '\bvim?\b' >/dev/null ; then direction="$(echo "${1#-}" | tr 'lLDUR' '\\hjkl')" # forward the keystroke to Vim tmux send-keys C-$direction else tmux select-pane "$@" fi This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,6 @@ function TmuxWinCmd(direction) exec 'silent !'.cmd redraw! " because `exec` fucked up the screen. why is this needed?? arrghh let g:tmux_is_last_pane = 1 else let g:tmux_is_last_pane = 0 endif -
mislav revised this gist
Mar 18, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,5 +16,5 @@ Here's how it should work: The solution has 3 parts: 1. In `~/.tmux.conf`, I bind the keys I want to execute a custom `tmux-vim-select-pane` command; 2. `tmux-vim-select-pane` checks if the foreground process in the current tmux pane is Vim, then forwards the original keystroke to the vim process. Otherwise it simply switches tmux panes. 3. In `.vimrc`, I set bindings for the same keystrokes to a custom function. The function tries to switch windows in the given direction. If the window didn't change, that means there are no more windows in the given direction inside vim, and it forwards the pane switching command to tmux by shelling out to `tmux select-pane`. -
mislav revised this gist
Mar 18, 2013 . 1 changed file with 16 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,19 @@ I use tmux splits (panes). Inside one of these panes there's a Vim process, and In Vim I have key bindings `C-h/j/k/l` set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with `C-W`.) I'd like to **use the same keystrokes for switching tmux panes**. An extra goal that I've solved with a dirty hack is to *toggle between last active panes* with `C-\`.  Here's how it should work: 1. If I'm in "vim window 2", going in left (`C-h`) or down (`C-j`) direction should switch windows _inside vim_. 2. However, if I'm in "vim window 3", going right (`C-l`) or down (`C-j`) should _select the next tmux pane_ in that direction. ## The solution The solution has 3 parts: 1. In `~/.tmux.conf`, I bind the keys I want to execute a custom `tmux-vim-select-pane` command; 2. `tmux-vim-select-pane` checks if the foreground process in the current tmux pane is Vim, then forwards the original keystroke to the Vim process. If there's no Vim process in the current pane, it simply switches tmux panes. 3. In `.vimrc`, I set bindings for the keystrokes to a custom function. The function tries to switch windows in the given direction. If the window didn't change, that means there are no more windows in the given direction inside vim, and it forwards the pane switching command to tmux by shelling out to `tmux select-pane`. -
mislav created this gist
Mar 18, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ I use tmux splits (panes). Inside one of these panes there's a Vim process, and it has its own splits (windows). In Vim I have key bindings `C-h/j/k/l` set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with `C-W`.) I'd like to **use the same keystrokes for switching tmux panes**.  This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ #!/usr/bin/env bash # Like `tmux select-pane`, but if Vim is running in the current pane it sends a # keystroke to Vim instead to let it decide whether it's going to switch windows # internally or switch tmux panes. set -e # gets the tty of active tmux pane active_tty="$(tmux list-panes -F '#{pane_active}#{pane_tty}' | grep '^1')" # checks if there's a foreground Vim process in attached to that tty if ps -t "${active_tty#*/tty}" -c -o 'state command' | grep '+' | grep -i 'vim' >/dev/null ; then direction="$(echo "${1#-}" | tr 'lLDUR' '\\hjkl')" # forward the keystroke to Vim tmux send-keys C-\[ C-$direction else tmux select-pane "$@" fi This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ # Smart pane switching with awareness of vim splits bind -n C-k run-shell 'tmux-vim-select-pane -U' bind -n C-j run-shell 'tmux-vim-select-pane -D' bind -n C-h run-shell 'tmux-vim-select-pane -L' bind -n C-l run-shell 'tmux-vim-select-pane -R' bind -n "C-\\" run-shell 'tmux-vim-select-pane -l' This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ let g:tmux_is_last_pane = 0 au WinEnter * let g:tmux_is_last_pane = 0 " Like `wincmd` but also change tmux panes instead of vim windows when needed. function TmuxWinCmd(direction) let nr = winnr() let tmux_last_pane = (a:direction == 'p' && g:tmux_is_last_pane) if !tmux_last_pane " try to switch windows within vim exec 'wincmd ' . a:direction endif " Forward the switch panes command to tmux if: " a) we're toggling between the last tmux pane; " b) we tried switching windows in vim but it didn't have effect. if tmux_last_pane || nr == winnr() let cmd = 'tmux select-pane -' . tr(a:direction, 'phjkl', 'lLDUR') exec 'silent !'.cmd redraw! " because `exec` fucked up the screen. why is this needed?? arrghh let g:tmux_is_last_pane = 1 echo cmd else let g:tmux_is_last_pane = 0 endif endfunction " navigate between split windows/tmux panes nmap <c-j> :call TmuxWinCmd('j')<cr> nmap <c-k> :call TmuxWinCmd('k')<cr> nmap <c-h> :call TmuxWinCmd('h')<cr> nmap <c-l> :call TmuxWinCmd('l')<cr> nmap <c-\> :call TmuxWinCmd('p')<cr>