Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center horizontally the contents of the open file in vim?

Tags:

vim

how do I make vim horizontally center the text of the open file?

I don't want to modify the file, just to change the way vim displays it.

To be more clear, when I open a file I currently have this situation:

|<------ textwidth=80 ------->|<-------------- padding -------------->|
|lorem ipsum dolor sit amet.. 
|dsdsda da dsa dsa 

What I'd like to have is the following:

|<--- padding/2 --->|<------ textwidth=80 ------->|<--- padding/2 --->|
|                    lorem ipsum dolor sit amet.. 
|                    dsdsda da dsa dsa 

Of course, for every value of textwidth and padding.

like image 546
Andrea Spadaccini Avatar asked Oct 18 '12 10:10

Andrea Spadaccini


3 Answers

Vim isn't meant to be a single, centered document editor (when programming, you want to fill every single pixel with relevant information), so there are only workarounds:

a) You can achieve a larger left margin by expanding the fold column. Unfortunately, this is limited to 12 character cells:

:let &foldcolumn = (&columns - &textwidth) / 2

b) You can create an empty padding window to the left (and potentially also to the right, for symmetry).

:execute 'topleft' ((&columns - &textwidth) / 2 - 1) . 'vsplit _paddding_' | wincmd p

The annoying window split can be cleared with:

:hi VertSplit guifg=bg guibg=NONE gui=NONE
like image 120
Ingo Karkat Avatar answered Oct 23 '22 05:10

Ingo Karkat


I think you could reach the point using screen. you can open three different windows tiled vertically with

CTRL+a , SHIFT+|

then move to the second one.

like image 20
Origama Avatar answered Oct 23 '22 04:10

Origama


Exist several plugins that allow you to get that look, most of them seem to be inspired by Writeroom editor for MacOS.

See for example this screenshot of the the VimRoom plugin, or just search the web for "vim writeroom plugin".

enter image description here

like image 4
gerlos Avatar answered Oct 23 '22 06:10

gerlos