Commit
Initial commit
Daniel Moch committed 4 years ago
(Tree)
Diffstat
doc/smartsplit.vim | 65 +++++++++++++++++++++++++++++++++++
plugin/smartsplit.vim | 83 +++++++++++++++++++++++++++++++++++++++++++++
doc/smartsplit.vim (created)
1
+*smartsplit.txt* You're lazy. Let Vim decide your split directions.
2
+
3
+Author: Daniel Moch <daniel@danielmoch.com>
4
+License: VIM LICENSE
5
+
6
+ *smartsplit*
7
+
8
+Yeah, you're aware of split/vsplit, new/vnew and the like. You use them
9
+because you have to, but you know there must be a better way. This is it.
10
+
11
+Vim, given it's old pedigree, tacitly assumes a standard terminal width of
12
+around 80 characters. In this environment it makes sense for Vim to assume any
13
+command that divides the current window should divide horizonally. But our
14
+monitors are often capable of more than twice the width of an old terminal, so
15
+this doesn't make sense any more.
16
+
17
+One sensible option, which this plugin adopts, is to make a best-guess at the
18
+width of the text displayed in the current window (see 'textwidth'. Then
19
+operations should default to vertical if there is enough horizonal room to
20
+display two splits side-by-side.
21
+
22
+This plugin provides :Help, :Split, :New, and :Buffer commands to replace
23
+their lower-case counterparts. It also sets 'diffopt' to split in either a
24
+horizontal or vertical direction, again depending on the horizontal space
25
+available.
26
+
27
+1. Commands |smartsplit-commands|
28
+2. About |smartsplit-about|
29
+
30
+=============================================================================
31
+1. Commands *smartsplit-commands*
32
+
33
+ *smartsplit-Split* *:Split*
34
+Split A smart version of the |:split| command. Open a new
35
+ split in the current tab. The direction is
36
+ determined in reference to the value of
37
+ 'textwidth' for the current buffer (defaulting to
38
+ 80). If the horizontal space is greater than twice
39
+ the current 'textwidth' value, then the split is
40
+ made vertically. Otherwise the split is
41
+ horizontal.
42
+
43
+ *smartsplit-New* *:New*
44
+New A smart version of |:new|. Horizontal versus
45
+ vertical splitting is determined as described in
46
+ |:Split|.
47
+
48
+ *smartsplit-Buffer* *:Buffer*
49
+Buffer A smart version of |:buffer|. Horizontal versus
50
+ vertical splitting is determined as described in
51
+ |:Split|.
52
+
53
+ *smartsplit-Help* *:Help*
54
+Help A smart version of |:help|. Horizontal versus
55
+ vertical splitting is determined as described in
56
+ |:Split|.
57
+
58
+=============================================================================
59
+2. ABOUT *smartsplit-about*
60
+
61
+More details can be found in README.md or by navigating to:
62
+
63
+ https://git.danielmoch.com/vim-smartsplit/about
64
+
65
+vim:tw=78:ts=8:ft=help:norl:
plugin/smartsplit.vim (created)
1
+"
2
+" TITLE: VIM-SMARTSPLIT
3
+" AUTHOR: Daniel Moch <daniel AT danielmoch DOT com>
4
+" LICENSE: VIM LICENSE
5
+" VERSION: 0.1.0-dev
6
+"
7
+if exists('g:loaded_smartsplit') || &cp
8
+ finish
9
+endif
10
+
11
+let g:loaded_smartsplit = 1
12
+let s:save_cpo = &cpo
13
+set cpo&vim
14
+
15
+function! s:WinWidth()
16
+ let l:textwidth = &tw ? (&tw + 8) : 80
17
+ echo l:textwidth
18
+ if &number
19
+ let l:numwidth = &numberwidth > len(line('$')) + 1 ?
20
+ \ &numberwidth : len(line('$')) + 1
21
+ else
22
+ let l:numwidth = 0
23
+ endif
24
+ return winwidth(0) > (2 * l:textwidth) + (2 * l:numwidth)
25
+endfunction
26
+
27
+function! s:ScratchBuffer() abort
28
+ let l:wincmd = s:WinWidth() ? 'vnew' : 'new'
29
+ exec l:wincmd
30
+ setlocal bufhidden=hide buftype=nofile noswapfile
31
+endfunction
32
+
33
+function! s:DiffOpt()
34
+ if s:WinWidth()
35
+ set diffopt+=vertical
36
+ else
37
+ set diffopt-=vertical
38
+ endif
39
+endfunction
40
+
41
+function! s:NewWindow(...)
42
+ if a:0 == 0
43
+ let l:filename = ''
44
+ else
45
+ let l:filename = a:1
46
+ endif
47
+ if s:WinWidth()
48
+ execute 'vnew '.l:filename
49
+ else
50
+ execute 'new '.l:filename
51
+ endif
52
+endfunction
53
+
54
+function! s:Help(topic)
55
+ if s:WinWidth()
56
+ execute 'vert help '.a:topic
57
+ else
58
+ execute 'help '.a:topic
59
+ endif
60
+endfunction
61
+
62
+function! s:Buffer(...)
63
+ let l:splitcmd = s:WinWidth() ? 'vsplit' : 'split'
64
+ execute l:splitcmd
65
+ if a:0 == 1
66
+ execute bufnr(a:1).'buffer'
67
+ endif
68
+endfunction
69
+
70
+augroup smartsplit
71
+ autocmd!
72
+ autocmd VimResized * call <sid>DiffOpt()
73
+ autocmd VimEnter * call <sid>DiffOpt()
74
+augroup END
75
+
76
+command! -complete=file -nargs=? New call <sid>NewWindow(<f-args>)
77
+command! -complete=help -nargs=1 Help call <sid>Help(<f-args>)
78
+command! -complete=buffer -nargs=1 Buffer call <sid>Buffer(<f-args>)
79
+command! Split call <sid>Buffer()
80
+
81
+let &cpo = s:save_cpo
82
+unlet s:save_cpo
83
+" vim: et sts=4 sw=4 tw=72