4

I'd like to use vim to edit long texts (prose / no code), in a well formatted way.

Let consider this file:

lorem_original screenshot

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:

not-perfect alkignement using par

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 ?

Giorgio Robino
  • 2,148
  • 6
  • 38
  • 59

2 Answers2

1

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.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • in facts $LANG=en_US.UTF-8 instead the text I reported is Italian. Using a english text par behave correctly. – Giorgio Robino Jan 28 '15 at 17:35
  • I installed Italian locale ($sudo locale-gen it_IT.UTF-8; export LANG='it_IT.UTF-8') and checked inside vim :language confirm vim understand now Italian (Lingua in uso: "LC_CTYPE=it_IT.utf8;LC_NUMERIC=C;LC_TIME=it_IT.utf8;LC_COLLATE=it_IT.utf8;LC_MONETARY=it_IT.utf8;LC_MESSAGES=it_IT.utf8;LC_PAPER=it_IT. utf8;LC_NAME=it_IT.utf8;LC_ADDRESS=it_IT.utf8;LC_TELEPHONE=it_IT.utf8;LC_MEASUREMENT=it_IT.utf8;LC_IDENTIFICATION=it_IT.utf8" ), nevertheless the above mentioned formatting still doesnt work. – Giorgio Robino Jan 29 '15 at 09:48
1

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:

enter image description here

tlehman
  • 5,125
  • 2
  • 33
  • 51
  • plus 1 for the screencast :-) but maybe leaving vim to use less is maybe not the best especially with a big file – Giorgio Robino Jan 29 '15 at 09:15
  • Maybe, I just tried it on a 13,052 line file (Sherlock Holmes) and it was nearly instananeous. However, I am pretty sure Emacs has justification built in somewhere, it might be worth checking out. – tlehman Jan 29 '15 at 18:04
  • thanks Tobi! I'm now trying to understand why par do not justify a text in Italian language (see comments here above http://stackoverflow.com/questions/28177598/how-to-align-justify-in-vim-editor/28202391?noredirect=1#comment44787166_28188169 ) – Giorgio Robino Jan 30 '15 at 09:54