
.vimrc で tw=80 に制限したファイルを編集すると、後で編集するときに行の長さがバラバラになってしまいます。例:
lets say for the sake of argument that this line hits 80 characters
there and continues on the next line as normal
編集後…
lets say for the sake of argument (edit edit edit edit) that this
line hits 80 characters
there and continues on the next line as normal
の代わりに
lets say for the sake of argument (edit edit edit edit) that this
line hits 80 characters there and continues on the next line as
normal
この動作を修正するにはどうすればいいのか知っている人はいますか?
答え1
gq
テキストの書式を変更するには、" " 通常モード コマンドを使用できます。これは、視覚的な選択範囲またはモーションで機能します。たとえば、 ap
"段落" (カーソルが置かれている現在の段落) を意味するテキスト オブジェクト " " (モーションの代わりに使用できます) を使用できます。
gqap
または、書式を変更する段落を視覚的に選択し、「gq
」と入力することもできます。
もう 1 つのトリックは、'formatoptions' オプションに "a" とオプションで "w" を追加することです。
:set formatoptions+=aw
これにより、「 」に頼ることなく、入力時に段落が自動的に再フォーマットされますgq
。
見る:
:help gq
:help auto-format
:help 'formatoptions'
:help motion.txt
答え2
探しているのは vi の formatoptions です。テキストの折り返しを有効にするには:
:set fo+= t
出典: