mi sento di raccomandare di mettere quanto segue nel tuo vimrc se questo è un problema normale:
nnoremap <leader>f gqip
Questo mappe la scorciatoia capo f (f è per "formato") per formattare il commento (considerato un paragrafo dopo impostazione di alcuni flag di formattazione) con gq che formatta il commento in base alla larghezza dell'opzione textwidth
o tw
correntemente impostata. Devi impostare textwidth nel tuo .vimrc con textwidth=80
.
Formatoptions è l'altra cosa con cui dovresti giocare, in particolare nel tuo caso aggiungendo le bandiere acq
con formatoptions+=acq
. Fai attenzione a rimuovere il flag t
con formatoptions-=t
perché questo comprenderà automaticamente tutto il codice, non solo i commenti riconosciuti. Dopo aver fatto tutto questo dovresti riuscire a premere f e formattare solo il commento, indipendentemente dal fatto che sia circondato da righe vuote.
Ecco le informazioni rilevanti su formatoptions in modo da poter fare le proprie scelte.
t Auto-wrap text using textwidth
c Auto-wrap comments using textwidth, inserting the current comment
leader automatically.
r Automatically insert the current comment leader after hitting
<Enter> in Insert mode.
o Automatically insert the current comment leader after hitting 'o' or
'O' in Normal mode.
q Allow formatting of comments with "gq".
Note that formatting will not change blank lines or lines containing
only the comment leader. A new paragraph starts after such a line,
or when the comment leader changes.
w Trailing white space indicates a paragraph continues in the next line.
A line that ends in a non-white character ends a paragraph.
a Automatic formatting of paragraphs. Every time text is inserted or
deleted the paragraph will be reformatted. See |auto-format|.
When the 'c' flag is present this only happens for recognized
comments.
Penso che sia sufficiente impostare textwidth = 80, poi GQ riformattare. –
Oh mio Dio, non posso credere sia così semplice, grazie! –
@DeepYellow ma sembra solo * carriage-returns * quando scrivi alla fine della riga, vero? Se aggiungi del testo all'inizio, non si sposta oltre il testo sulla riga successiva. O sto sbagliando? –