vimtutor学习 vim 基础
开始使用vimtutor
- vim 自带的一个教程
- 总共7节课,学完这7个 Lesson 基本就掌握了 vim 的所有基础操作
- 是完全可以跟着做的
vimtutor
Lesson 1
move the cursor 移动光标
- **要移动光标,请按照指示按H,J,K,L键。 **
- 为什么是这几个按键代码基础移动:因为这四个按键是你右手放的最近的几个键
- j (下,想象有个向下的勾)就在你的食指,食指的左边是 h(代表左),k(代表上),l (代表右,因为在最右边)
^
k Hint: The h key is at the left and moves left.
< h l > The l key is at the right and moves right.
j The j key looks like a down arrow.
v
学会退出 exit vim(新手注意)
:q, 退出(没有修改)
:q!,强制退出
:wq,保存退出
- ! NOTE: Before executing any of the steps below, read this entire lesson!!
- 注意:执行以下任何步骤之前,请阅读1.2整节课!!
- 退出步骤:
1. Press the <ESC> key (to make sure you are in Normal mode).
2. Type: :q! <ENTER>.
This exits the editor, DISCARDING any changes you have made.
3. Get back here by executing the command that got you into this tutor. That
might be: vimtutor <ENTER>
4. If you have these steps memorized and are confident, execute steps
1 through 3 to exit and re-enter the editor.
NOTE: :q! <ENTER> discards any changes you made. In a few lessons you
will learn how to save the changes to a file.
5. Move the cursor down to lesson 1.3.
1.按<ESC>键(以确保您处于正常模式)。
2.类型:: q! <enter>。
这将退出编辑器,丢弃您所做的任何更改。
3.通过执行使您加入此导师的命令来回到这里。 那
可能是:Vimtutor <Enter>
4.如果您记住这些步骤并有信心,请执行步骤
1至3退出并重新输入编辑器。
注意::q! <Enter>丢弃您所做的任何更改。 在您的几堂课中
将学习如何将更改保存到文件中。
5.将光标向下移至第1.3课。
编辑文本(delete character删除字符)
x
编辑文本(insert)
i:进入 insert 模式,按 ESC 返回到 Normal- Press i to insert text.
追加文本(append)
- ** Press A to append text. **
- A 能够到句子末尾进行添加操作(Insert模式)
编辑文件
- ** Use :wq to save a file and exit. **
总结
- 移动(h,j,k,l)--->normal 最常用
- 删除字符(x) ----->normal
- 编辑(i,A)---->insert模式
- 退出(:q,q!,wq)---->命令模式 command(:)

Lesson2
删除命令
- Type dw to delete a word.
1. Press <ESC> to make sure you are in Normal mode.
2. Move the cursor to the line below marked --->.
3. Move the cursor to the beginning of a word that needs to be deleted.
4. Type dw to make the word disappear.
- normal 模式下 dw 删除一个 word 单词
2.2
- d$ :删除行末位的所有单词字符
2.3
- d motion (删除+移动操作)
- d 是删除命令
- motion:例如$,w,e(e代表一个单词的结尾处)
j
2.4 use count
- dw (删一个单词)w 跳到一个单词首字母
- d2w (删2个单词) 2w 跳2个
- nw 跳 n 个单词,dnw 删除 n 个单词
- 3e:跳3个单词,同时到最后字符
2.5
- d number motion(w,e)
- d2w (删除2个单词)
2.6 对行进行操作
- 删除,copy,paste
- 对行删除:dd
Undo 操作
- 输错,操作错了我反悔了 undo
u:进行 undo 操作- redo:ctrl+r
Lesson3
3.1 put 命令
- 输入 p 会把之前删除的文本放到光标下面
3.2 替换命令
r:替换某一个字符 replace
3.3 change 操作
c: change 操作:(本质是 d+i:删除完自动进入 insert 模式):删除后重新输入
- ce:改变到一个单词结尾
3.4 c 的更多操作
- c [number] motion(w,e $)
- c2e : 改变到两个单词结尾
Lesson4
normal 模式下:
4.1 显示文件状态
- ctrl + g 显示文件状态和当前光标的行数
4.2 搜索命令
- 在 normal 模式下 使用
/, 然后使用n查找下一个匹配的pattern,N往回匹配 - ctrl + o 可以回到更早的位置
- ctrl + i 可以回到更新的位置
4.3 括号parenthese匹配搜索
- 光标在括号的某一个侧,然后按下% 进行匹配
4.4 替换命令
%s/old/new/g- old表示需要替换的字符或者单词,new 表示新的单词
- %s范围是是文件所有行数,%1,100s/old/new/g (这是代表替换的范围是1-100行)
- g 代表 全部替换,没有提示,gc 是可以提示我们是否替换某一个pattern。
Lesson 5
5.1 如何执行外部命令
- :! + 需要执行的终端命令
5.2 更多的写文件
- :w + filename 把编辑的 vim 保存为文件
5.3 选择文本
- normal 模式下按 v 选择文本
- ctrl + v 按列选
5.4 检索并合并文件
- :r + filename:将filename文件内容合并到当前编辑的文件
Lesson6
open 操作
- o 小写的 o 光标会跳到下一行并进入 insert 模式
- 大写的 O 光标会跳到上一行并进入 insert 模式
追加操作
- a 小写的 a ,在光标后进行插入(追加)
- A 大写的 A 会在一行末尾后进入 insert 模式
替换操作
- r 小写 r 只替换某一字符
- R 大写 R 一直替换
复制粘贴
- y (yank)复制一个字符,yy 复制一行,yw 复制一个单词。
- 想复制更多,可以先用 v 选择文本,然后按 y 复制
- p(paste) 粘贴
set 操作
- set ic :忽略大小写
- set noic:不忽略大小写
Lesson 7
获取帮助
:help 分出一个帮助文档窗口
- :help key
- ctrl+w 窗口切换(hjkl)
命令行补齐
- 命令模式下,:之后 ctrl+d 可以显示所有命令,tab 可以补全命令
- 上下键可以找历史命令
本文来自博客园,作者:勒勒乐了,转载请注明原文链接:https://www.cnblogs.com/matytan/articles/16758805.html

浙公网安备 33010602011771号