LoginSignup
11
9

More than 5 years have passed since last update.

vi > ファイル(LF改行)をwindowsの改行(CRLF改行)に変換する > :set ff=dos

Last updated at Posted at 2015-01-21

動作確認

CentOS 6.5 (32bit)
vim version 7.2

linux上で作成したファイルをWindows上へ持っていきたい時、改行をCR,LFにしないと改行がうまく機能しない。nkfなどのツールを使えば変換できるが、インストールをする必要があり、標準的なツールでできないか試してみた。

手順としては以下でよさそう。
1. vi linux.txt
2. :set ff=dos
3. :wq

これで

$file linux.txt
linux.txt: ASCII text

だったのが

$file linux.txt
linux.txt: ASCII text, with CRLF line terminators

となりCR,LFの行終端となっている。

ただし、ファイルを一つずつ手処理するので、大量のファイルがある時には向かない。



(追記)

noc06140728さんに教えていただいた方法を試してみました。
f1.txt,f2.txt,f3.txtがLF改行のファイルの場合で、他にf*.txtというファイルがない場合以下のようにすると一括で変換できるようです。

vi
:set hidden
:args f*.txt
:argdo set ff=dos|update
:q
11
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9