Skip to content

Instantly share code, notes, and snippets.

@tmelz
Created January 2, 2012 22:10
Show Gist options
  • Select an option

  • Save tmelz/1552327 to your computer and use it in GitHub Desktop.

Select an option

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>
@sunaku

sunaku commented Jan 3, 2012

Copy link
Copy Markdown

I suggest using the l: prefix for function-local variables because the a: prefix is intended for arguments passed to the function.

@tmelz

tmelz commented Jan 3, 2012

Copy link
Copy Markdown
Author

Done, thanks for the tip!

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