Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. nnoremap <c-w><c-j> :call <sid>smart_split('j')<cr>
  2. nnoremap <c-w><c-k> :call <sid>smart_split('k')<cr>
  3. nnoremap <c-w><c-h> :call <sid>smart_split('h')<cr>
  4. nnoremap <c-w><c-l> :call <sid>smart_split('l')<cr>
  5.  
  6. function! s:smart_split(cmd)
  7. " original window number
  8. let wn = winnr()
  9.  
  10. " try to move to other window
  11. exec 'wincmd ' . a:cmd
  12.  
  13. " do nothing if window changed
  14. if wn != winnr() | return | endif
  15.  
  16. " otherwise split vertical or horizontal based on a:cmd
  17. exec 'wincmd ' . (a:cmd =~# '[lh]' ? 'v' : 's')
  18.  
  19. " move to new window. You only need this 50% of time.
  20. exec 'wincmd ' . a:cmd
  21. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement