vim

テキスト処理

書き方

vim [file]

モードのある編集器で、そのまま打っても何も入りません。i で入力を始め、Esc の後に :wq で保存、:q! で破棄します。

よく使うオプション

オプション意味
:wqWrite the file and quit; :x does the same
:q!Quit and throw every change away
iEnter insert mode; Esc goes back to normal mode
ddDelete the current line; u undoes the last change
/wordSearch forward; n jumps to the next hit
:%s/old/new/gReplace throughout the file
-ROpen read-only so you cannot save by accident

vim +100 config.yml

Opens at line 100.

vim -d a.txt b.txt

Opens the two files side by side as a diff.

vim -R big.log

Reads a log without any risk of writing to it.

パイプでつないで使うのが本来の形です。ひとつで全部やるより、三つつないだ方が短くなります。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. vim は何をしますか。

モードのある編集器で、そのまま打っても何も入りません。i で入力を始め、Esc の後に :wq で保存、:q! で破棄します。

Q. どう打ちますか。

vim [file] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man vim にあります。このコマンドはテキスト処理の仲間です。

関連するコマンド

man ページ: man vim