Pin too long comment lines in Vim

I am looking for a convenient way to fix comments where line lengths exceed a certain number of characters in Vim. I am fine with this code manually, especially since it is not so often, plus refactoring of long lines is often a language, or even code dependent, but with comments this is pure burden.

What happens, I often notice some kind of problem in the comment, adjust one or two words, and the line spills out of, say, an 80-digit limit. I wrap the last word on the next line, and then it spills onto the next line and so on. Does anyone know a way to do this automatically in Vim?

+5
source share
1 answer

vimrc, :

nnoremap <leader>f gqip

f (f "format" ) ( ) gq, textwidth tw. .vimrc textwidth=80.

Formatoptions - , , , acq formatoptions+=acq. , t formatoptions-=t, , . , f , , .

Here is the relevant formatting information so you can make your own choice.

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.
+3
source

All Articles