Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM center text to screen, with left and right inactive borders

I use vim to edit text files. My screen is too wide and it's cumbersome to always look near left border of screen when editing. If you open a document in MS Office, the page is "centered" instead of left-aligned, and has non-active area borders on RHS and LHS. How do I get similar behavior from vim?

like image 490
user13107 Avatar asked Dec 10 '22 20:12

user13107


1 Answers

Here are a couple approaches that won't work too well:

First, if you read VIM: Show a 3 character border on left of window or MacVim: how do I set a left gutter (margin) for my buffers?, you might try this:

:set foldcolumn=50

This won't work, because the maximum value of foldcolumn is limited to 12.

Second, if you read How to create a border between the line numbers and text in Vim, you might try using numberwidth instead of foldcolumn:

:set numberwidth=50

But this won't work either, because the maximum value of numberwidth is limited to 10.

The best approach that will work, as far as I've been able to find, is https://superuser.com/q/537584/376367. See that question's answer for more details, but the summary is: create two vertical splits, and edit your file in the middle. If the vertical divider lines and tildes bother you, you could hide them with:

:highlight VertSplit guifg=bg guibg=bg
:highlight NonText   guifg=bg

Caution: if you use listchars, they also use NonText highlighting and will also be hidden by this trick.

like image 153
rmunn Avatar answered Apr 19 '23 23:04

rmunn