2007年10月15日月曜日

vim ウィンドサイズと位置の記憶と復帰

" Window位置の保存と復帰
if 1 && has('gui_running')
let s:infofile = '~/.window.vim'

function! s:WinPosSizeSave(filename)
redir @a
winpos
redir END
let px = substitute(@a, '.*X \(\d\+\).*', '\1', '') + 0
let py = substitute(@a, '.*Y \(\d\+\).*', '\1', '') + 0
execute 'redir! >'.a:filename
if px > 0 && py > 0
echo 'winpos '.px.' '.py
endif
echo 'set lines='.&lines.' columns='.&columns
redir END
endfunction

augroup WinPosSizeSaver
autocmd!
augroup END
execute 'autocmd WinPosSizeSaver VimLeave * call s:WinPosSizeSave("'.s:infofile.'")'
if filereadable(expand(s:infofile))
execute 'source '.s:infofile
endif
unlet s:infofile
endif

0 件のコメント: