Skip to content

Instantly share code, notes, and snippets.

@jonathanccalixto
Forked from mislav/_readme.md
Last active January 31, 2018 21:43
Show Gist options
  • Save jonathanccalixto/f1177d7eeebbcd141a69 to your computer and use it in GitHub Desktop.
Save jonathanccalixto/f1177d7eeebbcd141a69 to your computer and use it in GitHub Desktop.

Revisions

  1. @mislav mislav revised this gist Jul 21, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install.sh
    Original 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 \
    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
  2. @mislav mislav revised this gist Jun 25, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion tmux.conf
    Original 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'
    bind -n "C-\\" run-shell 'tmux-vim-select-pane -l'

    # Bring back clear screen under tmux prefix
    bind C-l send-keys 'C-l'
  3. @mislav mislav revised this gist Jun 22, 2013. 2 changed files with 5 additions and 5 deletions.
    8 changes: 4 additions & 4 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -21,11 +21,11 @@ The solution has 3 parts:

    ## Installation

    Requirements:
    * check `tmux -V` that you have **v1.8**

    * **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:
    * 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
    2 changes: 1 addition & 1 deletion install.sh
    Original 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/ea86d75e/bin/tmux-vim-select-pane \
    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
  4. @mislav mislav revised this gist Jun 22, 2013. 2 changed files with 11 additions and 8 deletions.
    12 changes: 9 additions & 3 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,12 @@ The solution has 3 parts:

    ## Installation

    ```sh
    curl -fsSL https://gist.github.com/mislav/5189704/raw/install.sh | bash -e
    ```
    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
    ```
    7 changes: 2 additions & 5 deletions install.sh
    Original 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://github.com/mislav/dotfiles/blob/ea86d75e/bin/tmux-vim-select-pane \
    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

    curl -fsSL https://github.com/mislav/vimfiles/blob/41bfa10b/plugin/tmux_navigator.vim \
    -o ~/.vim/plugin/tmux_navigator.vim --create-dirs
    chmod +x /usr/local/bin/tmux-vim-select-pane
  5. @mislav mislav revised this gist Apr 7, 2013. 2 changed files with 2 additions and 19 deletions.
    4 changes: 2 additions & 2 deletions install.sh
    Original 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://gist.github.com/mislav/5189704/raw/tmux-vim-select-pane.sh \
    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/33223b73/plugin/tmux_navigator.vim \
    curl -fsSL https://github.com/mislav/vimfiles/blob/41bfa10b/plugin/tmux_navigator.vim \
    -o ~/.vim/plugin/tmux_navigator.vim --create-dirs
    17 changes: 0 additions & 17 deletions tmux-vim-select-pane.sh
    Original file line number Diff line number Diff line change
    @@ -1,17 +0,0 @@
    #!/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 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
    else
    tmux select-pane "$@"
    fi
  6. @mislav mislav revised this gist Apr 1, 2013. 2 changed files with 1 addition and 1 deletion.
    File renamed without changes.
    2 changes: 1 addition & 1 deletion tmux.conf
    Original 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'
    bind -n "C-\\" run-shell 'tmux-vim-select-pane -l'
  7. @mislav mislav revised this gist Apr 1, 2013. 2 changed files with 11 additions and 10 deletions.
    10 changes: 10 additions & 0 deletions install.sh
    Original 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
    11 changes: 1 addition & 10 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -22,14 +22,5 @@ The solution has 3 parts:
    ## 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
    curl -fsSL https://gist.github.com/mislav/5189704/raw/install.sh | bash -e
    ```
  8. @mislav mislav revised this gist Apr 1, 2013. 2 changed files with 16 additions and 31 deletions.
    17 changes: 16 additions & 1 deletion readme.md
    Original 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 `.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`.
    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
    ```
    30 changes: 0 additions & 30 deletions vimrc
    Original file line number Diff line number Diff line change
    @@ -1,30 +0,0 @@
    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
    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>
  9. @mislav mislav revised this gist Mar 19, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tmux-vim-select-pane.sh
    Original 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 -t "${active_tty#1}" c -o 'state=,command=' | grep '+' | grep -iE '\bvim?\b' >/dev/null ; then
    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
  10. @mislav mislav revised this gist Mar 19, 2013. 2 changed files with 2 additions and 3 deletions.
    4 changes: 2 additions & 2 deletions tmux-vim-select-pane.sh
    Original 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#*/tty}" -c -o 'state command' | grep '+' | grep -i 'vim' >/dev/null ; then
    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-\[ C-$direction
    tmux send-keys C-$direction
    else
    tmux select-pane "$@"
    fi
    1 change: 0 additions & 1 deletion vimrc
    Original 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
    echo cmd
    else
    let g:tmux_is_last_pane = 0
    endif
  11. @mislav mislav revised this gist Mar 18, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions readme.md
    Original 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. 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`.
    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`.
  12. @mislav mislav revised this gist Mar 18, 2013. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion readme.md
    Original 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**.

    ![](http://f.cl.ly/items/3O0B0U2I041c420u163w/tmux%20vim%20panes%20hack.png)
    An extra goal that I've solved with a dirty hack is to *toggle between last active panes* with `C-\`.

    ![](http://f.cl.ly/items/3O0B0U2I041c420u163w/tmux%20vim%20panes%20hack.png)

    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`.
  13. @mislav mislav created this gist Mar 18, 2013.
    5 changes: 5 additions & 0 deletions readme.md
    Original 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**.

    ![](http://f.cl.ly/items/3O0B0U2I041c420u163w/tmux%20vim%20panes%20hack.png)
    17 changes: 17 additions & 0 deletions tmux-vim-select-pane.sh
    Original 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
    6 changes: 6 additions & 0 deletions tmux.conf
    Original 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'
    31 changes: 31 additions & 0 deletions vimrc
    Original 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>