Skip to content

Instantly share code, notes, and snippets.

@tmelz
Created January 2, 2012 22:10
Show Gist options
  • Save tmelz/1552327 to your computer and use it in GitHub Desktop.
Save tmelz/1552327 to your computer and use it in GitHub Desktop.
Vim: center current window in screen
let g:centerinscreen_active = 0
function! ToggleCenterInScreen(desired_width)
if g:centerinscreen_active == 0
let l:window_width = winwidth(winnr())
let l:sidepanel_width = (l:window_width - a:desired_width) / 2
exec("silent leftabove " . l:sidepanel_width . "vsplit new")
wincmd l
exec("silent rightbelow " . l:sidepanel_width . "vsplit new")
wincmd h
let g:centerinscreen_active = 1
else
wincmd h
close
wincmd l
close
let g:centerinscreen_active = 0
endif
endfunction
nnoremap <Leader>r :exec ToggleCenterInScreen(100)<CR>
@tmelz
Copy link
Author

tmelz commented Jan 3, 2012

Done, thanks for the tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment