进入vimtutor
# ubuntu system
vimtutor
lesson 2.3 : on operators and motions
许多处理文本的命令由 operators和motions组成,格式如下:
# 使用时operator和motion之间无空格,例如:dw
operator motion
常用的motions:
- w - 跳到下个单词的开始,不包含其第一个字符
- e - 跳到当前单词的结尾,包含其最后一个字符
- $ - 跳到当前行尾,包含最后一个字符
单独使用motion会使光标移动到对应位置,配合operator使用执行对应操作(例如:de 将删除光标位置到该单词结尾之间的内容)
lesson 2.7 : the undo command
- u : undo the last commands
- U : fix a whole line
- CTRL-R : redo the commands(undo the undo's) 撤销undo
lesson 2 SUMMARY
-
To delete from the cursor up to the next word type: dw
-
To delete from the cursor up to the end of the word type: de
-
To delete from the cursor to the end of a line type: d$
-
To delete a whole line type: dd
-
To repeat a motion prepend it with a number: 2w
-
The format for a change command is:
operator [number] motion
where:
operator - is what to do, such as d for delete
[number] - is an optional count to repeat the motion
motion - moves over the text to operate on, such as w (word),
e (end of word), $ (end of the line), etc. -
To move to the start of the line use a zero: 0
-
To undo previous actions, type: u (lowercase u)
To undo all the changes on a line, type: U (capital U)
To undo the undo's, type: CTRL-R
lesson 3.3 the change operator
- ce - deletes the word and places you in Insert mode.
- cc - deletes the whole line and places you in Insert mode.
lesson 4.2 the search command
# 例如搜索 asimov
/asimov
- n - 向下搜索
- N - 向上搜索
可以使用
?
代替/
进行反方向搜索
vim有一个jump list的概念,这个list是光标移动的历史记录,以下组合键可以帮助在该list上移动
ctrl+o
返回上一次光标所在位置ctrl+i
调整到jump list中当前记录的下一个记录
NOTE: 可以使用
set wrapscan
选项使 Vim 在到达文件末尾时回到文件顶部进行搜索。要关闭此功能,执行set nowrapscan
lesson 4.3 matching parentheses search
输入%
可找到匹配的括号
lesson 4.4 the substitute command
# 在本行中搜索old,然后用new进行替换(仅替换第一个old)
:s/old/new
# 在本行中搜索old,然后用new进行替换(本行中的old全部被替换为new)
:s/old/new/g
# 下面的 #,# 代表执行替换的范围(行号,行号)
:#,#s/old/new/g
# 对整个文件执行替换
:%s/old/new/g
# 对整个文件执行替换,并进行提示(是否执行替换)
:%s/old/new/gc
标签:vimtutor,motion,old,undo,学习,笔记,new,lesson,type
From: https://www.cnblogs.com/asimov1024/p/17904680.html