This was originally posted on my programming blog.
I use vim for absolutely everything that I reasonably can. When editing code I typically have a vertical split with files open in both panes - so there is content across the whole screen. But when I'm writing non-code text I usually only have one file open and I like to keep an 80-column margin. This means I have a relatively narrow column of writing all the way on the left side of the screen and it feels and looks weird.
I like to get it centered left-to-right on my full-screen vim window. This is how I accomplish that.
Check out the original post to learn more. For the impatient, here's a snippet:
" centers the current pane as the middle 2 of 4 imaginary columns " should be called in a window with a single pane function CenterPane() lefta vnew wincmd w exec 'vertical resize '. string(&columns * 0.75) endfunction " optionally map it to a key: " nnoremap <leader>c :call CenterPane()<cr>
Let me know if you find it to be broken in some situations or think it can be improved. Or better yet, if you found a better way to do the same!