1 " ZoomWin: Brief-like ability to zoom into/out-of a window
3 " modified by Charles Campbell
5 " History: see :he zoomwin-history
7 " ---------------------------------------------------------------------
8 if &cp || exists("s:loaded_zoomwin")
11 let s:loaded_zoomwin= 1
13 " ---------------------------------------------------------------------
15 if !hasmapto("<Plug>ZoomWin")
16 nmap <unique> <c-w>o <Plug>ZoomWin
18 nnoremap <silent> <script> <Plug>ZoomWin :set lz<CR>:call ZoomWin()<CR>:set nolz<CR>
19 com! ZoomWin :set lz|silent call ZoomWin()|set nolz
21 au VimLeave * call <SID>CleanupSessionFile()
23 " ---------------------------------------------------------------------
25 " ZoomWin: toggles between a single-window and a multi-window layout
26 " The original was by Ron Aaron and has been extensively
27 " modified by Charles E. Campbell.
29 " let g:decho_hide= 1 "Decho
30 " call Dfunc("ZoomWin() winbufnr(2)=".winbufnr(2))
32 let keep_hidden = &hidden
33 let keep_write = &write
34 if &wmh == 0 || &wmw == 0
42 " there's only one window - restore to multiple-windows mode
44 if exists("s:sessionfile") && filereadable(s:sessionfile)
45 let sponly= s:SavePosn(0)
47 " read session file to restore window layout
50 exe 'silent! so '.s:sessionfile
51 let v:this_session= s:sesskeep
53 if exists("s:savedposn1")
54 " restore windows' positioning and buffers
55 windo call s:RestorePosn(s:savedposn{winnr()})|unlet s:savedposn{winnr()}
56 call s:GotoWinNum(s:winkeep)
60 if line(".") != s:origline || virtcol(".") != s:origcol
61 " If the cursor hasn't moved from the original position,
62 " then let the position remain what it was in the original
63 " multi-window layout.
64 call s:RestorePosn(sponly)
67 " delete session file and variable holding its name
68 call delete(s:sessionfile)
73 else " there's more than one window - go to only-one-window mode
75 let s:winkeep = winnr()
76 let s:sesskeep = v:this_session
77 let s:origline = line(".")
78 let s:origcol = virtcol(".")
80 " doesn't work with the command line window (normal mode q:)
81 if &bt == "nofile" && expand("%") == "command-line"
82 echoerr "***error*** ZoomWin doesn't work with the command line window"
83 " call Dret("ZoomWin")
87 " save window positioning commands
90 windo let s:savedposn{winnr()}= s:SavePosn(1)
91 call s:GotoWinNum(s:winkeep)
93 " set up name of session file
94 let s:sessionfile= tempname()
98 let &ssop = 'blank,help,winsize'
99 exe 'mksession! '.s:sessionfile
101 exe "new! ".s:sessionfile
102 v/wincmd\|split\|resize/d
106 let &ssop = ssop_keep
112 " restore user option settings
113 let &hidden= keep_hidden
114 let &write = keep_write
115 if exists("keep_wmw")
119 " call Dret("ZoomWin")
122 " ---------------------------------------------------------------------
124 " SavePosn: this function sets up a savedposn variable that
125 " has the commands necessary to restore the view
126 " of the current window.
127 fun! s:SavePosn(savewinhoriz)
128 " call Dfunc("SavePosn(savewinhoriz=".a:savewinhoriz.") file<".expand("%").">")
129 let swline = line(".")
131 let swwline = winline()-1
132 let swwcol = virtcol(".") - wincol()
133 let savedposn = "silent b ".winbufnr(0)."|".swline."|silent norm! z\<cr>"
135 let savedposn= savedposn.":silent norm! ".swwline."\<c-y>\<cr>:silent norm! zs\<cr>"
137 let savedposn= savedposn.":silent call cursor(".swline.",".swcol.")\<cr>"
141 let savedposn= savedposn.":silent norm! ".swwcol."zl\<cr>"
144 " handle certain special settings for the multi-window savedposn call
145 " bufhidden buftype buflisted
148 let settings="bh=".&bh
152 let settings= settings." nobl"
156 let settings= settings." bt=".&bt
160 let savedposn= savedposn.":setlocal ".settings."\<cr>"
164 " call Dret("SavePosn savedposn<".savedposn.">")
168 " ---------------------------------------------------------------------
170 " s:RestorePosn: this function restores noname and scratch windows
171 fun! s:RestorePosn(savedposn)
172 " call Dfunc("RestorePosn(savedposn<".a:savedposn.">) file<".expand("%").">")
174 " call Dret("RestorePosn")
177 " ---------------------------------------------------------------------
179 " CleanupSessionFile: if you exit Vim before cleaning up the
180 " supposed-to-be temporary session file
181 fun! s:CleanupSessionFile()
182 " call Dfunc("CleanupSessionFile()")
183 if exists("s:sessionfile") && filereadable(s:sessionfile)
184 " call Decho("sessionfile exists and is readable; deleting it")
185 silent! call delete(s:sessionfile)
188 " call Dret("CleanupSessionFile")
191 " ---------------------------------------------------------------------
193 " GotoWinNum: this function puts cursor into specified window
194 fun! s:GotoWinNum(winnum)
195 " call Dfunc("GotoWinNum(winnum=".a:winnum.") winnr=".winnr())
196 if a:winnum != winnr()
197 exe a:winnum."wincmd w"
199 " call Dret("GotoWinNum")
202 " ---------------------------------------------------------------------