vim
テキスト処理
書き方
vim [file]モードのある編集器で、そのまま打っても何も入りません。i で入力を始め、Esc の後に :wq で保存、:q! で破棄します。
よく使うオプション
| オプション | 意味 |
|---|---|
| :wq | Write the file and quit; :x does the same |
| :q! | Quit and throw every change away |
| i | Enter insert mode; Esc goes back to normal mode |
| dd | Delete the current line; u undoes the last change |
| /word | Search forward; n jumps to the next hit |
| :%s/old/new/g | Replace throughout the file |
| -R | Open read-only so you cannot save by accident |
例
vim +100 config.ymlOpens at line 100.
vim -d a.txt b.txtOpens the two files side by side as a diff.
vim -R big.logReads 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