Lec 3 Vim基础
为什么要学习Vim?
流行的graphic-based editor: VScode
流行的cmd-based editor: Vim
Vim 号称 match the speed at which you think,只接受键盘输入。
Vim as a modal editor
Vim有不同的模式,包括Normal, Insert(i), Replace®, Visual(v), Command-line(😃
Normal: read and navigation
从normal 出发,输入对应字母切换mode,esc回到normal.
基本的工作流
vim README.md #使用vim打开文件,初始为normal模式,只读
i #进入insert 模式并编辑
u # undo
esc #推出insert 模式
:#进入command line 模式
wq #write and quit 保存并退出, 或者w只保存
q #不保存文件并且quit
注意,若中途使用crtl+z
退出,则会自动产生缓冲文件如 .README.md.swp, 若多次不正常退出会产生 .swo 等等(按照字母倒序)。对此,可以
ls -a #查看隐藏文件
rm .README.md.sw* #删除所有格式为sw*的文件
Vim as a programming language
可以定义一些快捷键和宏,甚至定义一些函数
移动快捷键
h,j,k,l #光标左下上右
4k #向上移动4line,同理nhjkl
w,b,e #next word, begining of the word, end of the word
0,$ #begining of the line, end of the line
crtl u, crtl d# up and down a page
gg, G # beginging of the file, end of the file
f+character # 在当前line光标之后中查找
F+character # 在当前line光标之前中查找
/ + word # search more powerful
编辑快捷键
o # insert line below
dw #delete word, dd delete line
y # copy one character, yw copy the word, yy copy the lin
p # paste
常用copy paste 工作流
v #进入visual 模式并开始选择字符
V #一次可以选择一line
y #copy 并回到normal
p # paste
. #重复上一次的命令
其他feature包括modifier等可以再次组合以上快捷键
也可以打开~/.vimrc 自定义或者复制别人写好的文件