MIT CS Missing-Semester Lec3

本文介绍了Vim,一款以速度见长的基于键盘的文本编辑器,涵盖了其不同模式、基本工作流程、快捷键以及编程语言特性,包括如何处理隐藏文件和自定义设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 自定义或者复制别人写好的文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值