Reputation: 2265
I'd like to use vim to edit long texts (prose / no code), in a well formatted way.
Let consider this file:
I can use sentences, paragraphs, etc. vim's features but the long sentences formatting isa bit ugly/poor readable.
So I'd like to have a some justification alignement with strict fixed colums width (let say columns = exactly 100).
I done some tests instlalling par
unix command line utility (sudo apt-get install par
) and setting vim to use it (with 'justify' flag):
:set formatprg=par\ jw100
and doing vim command:
gqG
but without a perfect joy, see screenshot here:
as you see I don't have an exact justification to 100 chars. why ?! It could be depend because par do not recognize some >8bit chars (of Italian language text here) ?
In fact there is a second issue: I don't want to permanently convert the original text in an aligned elaboration that destroy original sentence (introducing blanks/new line), but i would just VIEW the text leaving the original text untouched. There is a way to do that formatted view mode ?
Upvotes: 4
Views: 2866
Reputation: 378
A regex to achieve this:
:%s/\([^,]\{100}\)/\1\r/g
Also could place hyphen
at end-of-line split words with:
:%s/\(\w\)$\n\(\w\)/\1-\r\2/g
And so on and so forth.
Upvotes: 0
Reputation: 5167
To temporarily use par
on your file, make sure you've saved with :w
and then use :!par jw100 <% | less
, it will show you a readonly scrollable 100-char justified version of your file. When you are done, hit q and then Enter
Here's an example on some Lorem Ipsum text:
Upvotes: 1
Reputation: 172530
Vim has :set wrap
, and that's it. Remember, it's not a WYSIWYG editor, so viewing as justified text is out of scope.
You would indeed have to convert the physical text (back and forth). If the par
utility doesn't work (I think it should deal with UTF-8 encoded text; check your $LANG
value for that), you could also give the $VIMRUNTIME/macros/justify.vim
script that ships with Vim a try.
Upvotes: 1