vim的使用

# 撤回
u 
# 第一行
gg
# 回到原来的位置
ctrl + o
# 最后一行
G
#一页一页翻
f 
# 当前行首
0
# 当前行尾
$
# 切换到第n行
:n
# 相对于当前行第几行行尾
n$
# 复制
yy
# 复制n行
yyn
#代表的意思是复制153行到167行的内容到172行
:153,167 co 172
#代表的意思是复制第8行的内容到12行后面
:8 co 12
# 粘贴
pp
# 删除一个字符
x
# 删除一行(所在行)
dd
# 删除n行,n为数字。删除光标所在的向下n行,例如20dd则是删除光标所在的向下20行20dd
ndd
#删除光标所在到第一行的所有数据
d1G
#删除光标所在到最后一行的所有数据
dG
#删除光标所在处,到该行的最后一个字符
d$
#那个是数字0,删除光标所在到该行的最前面的一个字符
d0
#n为数字,从当前字符开始,连续向后删除n个字符
nx
# 搜索
:/keyword 
# vim中用man搜索 api, 如accept
:!man 2 api
# 查询man手册
光标移到api name上,shift+n+k
# 上一个
N
下一个
n
# 批量锁进
21,24 >
21,24 <
# 退出不做任何修改
q
# 保存退出
wq!

替换操作

:s/<find-this>/<replace-with-this>/<flags>

eg:

1 :%s/foo/bar/g  # 在全局范围内(%)查找foo并将之替换为bar,所有出现都会被替换(g)
2 :s/foo/bar/g  # 在当前行内查找foo并将之替换为bar,所有出现都会被替换(g)
3 :'<,'>s/foo/bar/g  # 在选区内进行替换,Visual模式下选择区域后输入会自动补全'<,'>

下面是一些可以加的flag. for example, :s/cat/dog/gi 会把cat.Cat() 变成 dog.dog().

  g —global replace: replace every occurrence of the pattern, not just the first one

  c —confirm each substitution: prompt the user before replacing the text

  e —do not show errors if no matches are found

  i —ignore case: make the search case-insensitive

  I —make the search case-sensitive

  最后说一个小tip: 程序员喜欢用foo和bar指代变量名: foo bar -> Fucked Up Beyond All Repair 完全无法修补。

results matching ""

    No results matching ""