Vim
基础命令
Normal 模式
h
j
k
l
: 左下上右u
: 撤销d
: 删除dd
: 删除当前行:set number
: 显示行号(set number 可以简写为 set nu):set nonumber
: 隐藏行号(set nonumber 可以简写为 set nonu)
查找及替换
/
: 搜索n/N
: 下一个/上一个搜索结果:s/old/new/g
: 替换当前行中的所有 old 为 new
:{作用范围}s/{目标}/{替换}/{替换标志}
作用范围包括:
.
: 当前行1,5
: 1 到 5 行%
: 所有行
替换标志包括:
g
: 全局替换c
: 替换前询问(y/n/a/q/l 分别表示:yes/no/all/quit/last)
内容编辑
yy
: 复制当前行p
: 粘贴P
: 粘贴到当前行的前面o
: 在当前行下面插入新行x
: 删除当前字符X
: 删除前一个字符r
: 替换当前字符
翻页
Ctrl + f
: 向下翻页Ctrl + b
: 向上翻页
跳转
gg
: 跳转到文件开头GG
: 跳转到文件结尾
Visual Block 模式
按下
Ctrl + v
进入 Visual Block 模式 Visual Block 模式下,可以选中一个矩形区域,然后对这个区域进行操作