Commit

Add a CmdSplit command as a :vertical counterpart

Pre-pending a command that creates splits with `:vertical` makes it
create vertical instead of horizontal splits. Adding a `:CmdSplit`
command enables the splits to be smart instead. This lets tools like
tpope/vim-fugitive's `Gstatus` respect your screen real-estate.
Daniel Moch committed 4 years ago (Tree)

Diffstat

 doc/smartsplit.vim | 5 +++++
 plugin/smartsplit.vim | 9 +++++++++

doc/smartsplit.vim

55 55 vertical splitting is determined as described in
56 56 |:Split|.
57 57
58 + *smartsplit-CmdSplit* *:CmdSplit*
59 +CmdSplit {cmd} A smart version of |:vertical|. Horizontal versus
60 + vertical splitting is determined as described in
61 + |:Split|.
62 +
58 63 =============================================================================
59 64 2. ABOUT *smartsplit-about*
60 65

plugin/smartsplit.vim

66 66 endif
67 67 endfunction
68 68
69 +function! s:CmdSplit(command)
70 + if s:WinWidth()
71 + execute 'vertical '.a:command
72 + else
73 + execute a:command
74 + endif
75 +endfunction
76 +
69 77 augroup smartsplit
70 78 autocmd!
71 79 autocmd VimResized * call <sid>DiffOpt()
. . .
75 83 command! -complete=file -nargs=? New call <sid>NewWindow(<f-args>)
76 84 command! -complete=help -nargs=1 Help call <sid>Help(<f-args>)
77 85 command! -complete=buffer -nargs=1 Buffer call <sid>Buffer(<f-args>)
86 +command! -complete=command -nargs=1 CmdSplit call <sid>CmdSplit(<f-args>)
78 87 command! Split call <sid>Buffer()
79 88
80 89 let &cpo = s:save_cpo