1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vim Macで改行に置換させる方法。文字コードとファイルフォーマットの視点から。

Posted at

改行に置換するとき、\r^Mを使用する
Ctrl + v returnを押すと^Mを入力することができる。
検索の場合は\nを入力する。

以下の2つは同じこと

:%s/,/,\r/g

:%s/,/,^M/g

検索の場合と置換の場合で、改行に該当する文字コードがことなるのは、文字コードの定義と、ファイルフォーマットの定義が異なるから。

改行コードは処理系定義

OS 記号 ASCII プログラム上
Windows <CR><LF> 0A0D \r\n
Linux <LF> or ^@ 0A \n
Mac <CR> or ^M 0D \r

文字コード、ファイルフォーマットの確認方法

vimの編集中に以下のコマンド

文字コードの確認

:set enc?

ファイルフォーマットの確認

:set ff?

参考

vimで改行への置換を行うには\r、改行を置換するには\nを用いるのは何故か - rohaniのブログ

1
2
0

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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?