これが定期的な問題である場合は、次を vimrc に追加することをお勧めします。
nnoremap <leader>f gqip
textwidth
これは、現在設定されているまたはtw
オプションの幅になるようにコメントをフォーマットする gq を使用して、コメント (いくつかの formatoption フラグを設定した後に段落と見なされる) をフォーマットするためのリーダー f ショートカット (f は「フォーマット」を表す) をマップします。.vimrc で textwidth を設定する必要がありますtextwidth=80
。
Formatoptions は、特にあなたの場合、acq
フラグをformatoptions+=acq
. 認識されたコメントだけでなく、すべてのコードが自動的にラップされるため、t
フラグを削除するように注意してください。formatoptions-=t
これをすべて実行した後、空白行で囲まれているかどうかに関係なく、コメント内でのみ f を押してフォーマットできるはずです。
ここに formatoptions に関する関連情報があるので、自分で選択できます。
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.