larghezza del testo vim riformattare
-
27-10-2019 - |
Domanda
voglio riformattare il mio file in modo che la larghezza massima linea è 79. Ho fatto :set tw=79
e gggqG
ed i risultati non erano quello che mi aspettavo. Quando una linea è inferiore al 79 col, caratteri dalla linea di sotto di essa si muovono su e linee con oltre 79 col non si rompono in due linee.
modifica:. Beh, io ero semi-sbagliato nel senso che non le linee di interruzione oltre 79 se non in linea con asterischi
--CONVENTIONS**************************************************************************************
Inoltre si sposta ancora caratteri quando la linea è <79.
Soluzione
One possible solution, although not the best one.
Undefine formatexpr
and let external fold
program to format your text to 79 characters width.
:set formatexpr=
:set formatprg=fold\ -w\ 79
And now:
gg # Go to beginning of file.
gq # Format until...
G # End of file.
And last remove those carriage returns (^M):
:%s/\r//g
In my test it changed some accented characters and some other lines were mangled, but try it yourself. Else you may write your own format function and use it with formatexpr
option.
Altri suggerimenti
Put empty line between different paragraphs. Then do the reformat.