VIM で、非常に長い行を複数の行に分割するにはどうすればよいでしょうか? 質問する

VIM で、非常に長い行を複数の行に分割するにはどうすればよいでしょうか? 質問する

たとえば、VIM エディタに非常に長い行 (約 300 文字以上) があるとします。単語の境界がおよそ 80 文字で区切られるように、これを複数の行に分割するにはどうすればよいでしょうか。

例:

This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line

This is a really long line 
This is a really long line
This is a really long line
This is a really long line
This is a really long line
This is a ...

ベストアンサー1

Vim では、これを非常に簡単に実行できます (単語の境界で行を折り返します)。

gq{motion} % format the line that {motion} moves over
{Visual}gq % format the visually selected area
gqq        % format the current line
...

:help gqとをチェックしてみることをお勧めします:help gw

また、textwidth ( tw) を設定すると、入力中に超過したときに自動的に改行されます。 これgqは でも使用されますが、無効にすると、gqウィンドウ サイズまたは 79 のどちらかが先に達したときに改行されます。

:set tw=80

テキスト幅を含めるようにフォーマット オプションを設定すると、vim は tw 設定で自動的に中断します。

:set fo+=t

おすすめ記事