|
if $TMUX != '' |
|
" integrate movement between tmux/vim panes/windows |
|
|
|
fun! TmuxMove(direction) |
|
" Check if we are currently focusing on a edge window. |
|
" To achieve that, move to/from the requested window and |
|
" see if the window number changed |
|
let oldw = winnr() |
|
silent! exe 'wincmd ' . a:direction |
|
let neww = winnr() |
|
silent! exe oldw . 'wincmd' |
|
if oldw == neww |
|
" The focused window is at an edge, so ask tmux to switch panes |
|
if a:direction == 'j' |
|
call system("tmux select-pane -D") |
|
elseif a:direction == 'k' |
|
call system("tmux select-pane -U") |
|
elseif a:direction == 'h' |
|
call system("tmux select-pane -L") |
|
elseif a:direction == 'l' |
|
call system("tmux select-pane -R") |
|
endif |
|
else |
|
exe 'wincmd ' . a:direction |
|
end |
|
endfun |
|
|
|
function! TmuxSharedYank() |
|
" Send the contents of the 't' register to a temporary file, invoke |
|
" copy to tmux using load-buffer, and then to xclip |
|
" FIXME for some reason, the 'tmux load-buffer -' form will hang |
|
" when used with 'system()' which takes a second argument as stdin. |
|
let tmpfile = tempname() |
|
call writefile(split(@t, '\n'), tmpfile, 'b') |
|
call system('tmux load-buffer '.shellescape(tmpfile).';tmux show-buffer | xclip -i -selection clipboard') |
|
call delete(tmpfile) |
|
endfunction |
|
|
|
function! TmuxSharedPaste() |
|
" put tmux copy buffer into the t register, the mapping will handle |
|
" pasting into the buffer |
|
let @t = system('xclip -o -selection clipboard | tmux load-buffer -;tmux show-buffer') |
|
endfunction |
|
|
|
|
|
nnoremap <silent> <c-w>j :silent call TmuxMove('j')<cr> |
|
nnoremap <silent> <c-w>k :silent call TmuxMove('k')<cr> |
|
nnoremap <silent> <c-w>h :silent call TmuxMove('h')<cr> |
|
nnoremap <silent> <c-w>l :silent call TmuxMove('l')<cr> |
|
nnoremap <silent> <c-w><down> :silent call TmuxMove('j')<cr> |
|
nnoremap <silent> <c-w><up> :silent call TmuxMove('k')<cr> |
|
nnoremap <silent> <c-w><left> :silent call TmuxMove('h')<cr> |
|
nnoremap <silent> <c-w><right> :silent call TmuxMove('l')<cr> |
|
|
|
vnoremap <silent> <esc>y "ty:call TmuxSharedYank()<cr> |
|
vnoremap <silent> <esc>d "td:call TmuxSharedYank()<cr> |
|
nnoremap <silent> <esc>p :call TmuxSharedPaste()<cr>"tp |
|
vnoremap <silent> <esc>p d:call TmuxSharedPaste()<cr>h"tp |
|
set clipboard= " Use this or vim will automatically put deleted text into x11 selection('*' register) which breaks the above map |
|
|
|
" Quickly send text to a pane using f6 |
|
nnoremap <silent> <f6> :SlimuxREPLSendLine<cr> |
|
inoremap <silent> <f6> <esc>:SlimuxREPLSendLine<cr>i " Doesn't break out of insert |
|
vnoremap <silent> <f6> :SlimuxREPLSendSelection<cr> |
|
|
|
" Quickly restart your debugger/console/webserver. Eg: if you are developing a node.js web app |
|
" in the 'serve.js' file you can quickly restart the server with this mapping: |
|
nnoremap <silent> <f5> :call SlimuxSendKeys('C-C " node serve.js" Enter')<cr> |
|
" pay attention to the space before 'node', this is actually required as send-keys will eat the first key |
|
|
|
endif |
|
|
Hey, I got a question for you at this position (line 11): https://gist.github.com/tarruda/5158535#file-vimrc-L11
I don't think this line does anything... In order to go to a target window you must use
:{num}wincmd w
as far as I am aware.You really don't need to the starting window index. (and then re-set to target window it if the check passes). Just leave it.