Vim 是一个功能强大且灵活的文本编辑器,是 Vi 编辑器的增强版,本文将介绍 Vim 的基本使用方法和常见操作技巧。(本文将以 Ubuntu 版本示例)
Vim 的使用
打开文件
// 打开一个已存在的文件,直接进入文件
root@ubuntu:/home# vim exists.txt
~~"exists.txt" 0L, 0B 0,0-1 All
// 打开一个不存在的文件,直接进入文件,底部显示“New”
root@ubuntu:/home# vim absent.txt
~~"absent.txt"[New]0,0-1 All
常用选项
+/关键字
// 打开文件后,光标会出现在关键字的行首
root@ubuntu:/home# vim +/exists exists.txt
1.VERB 存在;实际上有
**I**f something exists, it is present in the world as a real thing.
-d 选项
// 比较两个文件,两个文件不同的部分会用红色的高亮显示
root@ubuntu:/home# vim -d f1 f2
111111111111111111111|1111111111122222222222222222|222222222222333333333333333333333333|33333333333444444444444444444444444|444444444445555555555555555555555|555555555556666666666666666666|6666665666666------------------------------|