w会从光标处定向到下一个单词(以空格和中英文切换为分割符)的首字母。
e从光标处定向到该/下一个单词的last字母
^从光标处定向到行首(效果同0)
$从光标处定向到行尾
以上定位符可以单独使用用来移动光标,也可以与下面的操作符结合使用
c——是change的意思——cc:修改当前行,即删除当前行并进入Insert Model
d——delete——dd:删除当前行
y——copy——yy:复制当前行
p——paste
r——replace
x——
??
以上(除了p和0)都可以和字母共用达到针对多个单词或者多行的操作,如:
3[w/e/$/cc/dd/yy/u] 移动到第四个word第一个字母/移动到第三个word最后一个字母/移动到三行后末尾/删除光标及以下2行并进入insert mode/删除光标及以下2行/粘帖光标行及以下两行到粘帖板/恢复三次操作之前的状态
3^不管用??
why??Maybe it's just because foreword is not allowed but backward.
[c/d/y]2[w/e/$]
y
^w(also it does not work)/
3rm把当前光标后面的三个位置全部替换成m
3x删除当前光标后的三个位置
从downcase到upcase的过程也是从单个字符到整行的过程:
O,o
A,a
I,i
翻页:
Ctrl+f 向下翻页
Ctrl+b 向上翻页
Ctrl+r == :redo 重复最近一次撤销的修改
查看文件位置和当前光标的位置
Type CTRL-G to show your location in the file and the file status.
Press G to move you to the bottom of the file.
Type gg to move you to the start of the file.
Type the row num where u wanna go then Press G to move u to the expected row
Type gg to move you to the start of the file.
Type the row num where u wanna go then Press G to move u to the expected row
查找
Type / or ? followed by a phrase to search for the phrase, / foreword and ? backward.
To search for the same phrase again, simply type n .
To search for the same phrase in the opposite direction, type N .
To search for the same phrase in the opposite direction, type N .
To go back to where you came from press CTRL+o (Keep Ctrl down while pressing the letter o). Repeat to go back further. CTRL+i goes forward.
查找对应括号
Type % to find a matching ),], or } .
1. Place the cursor on any (, [, or { in the line below marked --->.
2. Now type the % character.
1. Place the cursor on any (, [, or { in the line below marked --->.
2. Now type the % character.
替换
Type :s/old/new to substitute 'new' for 'old' just, changing the first occurrence of "old" in the line. .
Type :s/old/new/g to substitute 'new' for 'old' in the entire line, changing all occurrences of "old" in the line.
Type :#,#s/old/new/g where #,# are the line numbers of the range of lines where the substitution is to be done.
Type :%s/old/new/g to change every occurrence in the whole file.
Type :%s/old/new/gc to find every occurrence in the whole file, with a prompt whether to substitute or not.
Type :%s/old/new/g to change every occurrence in the whole file.
Type :%s/old/new/gc to find every occurrence in the whole file, with a prompt whether to substitute or not.
执行命令
Type :! followed by an external command to execute that command.
For example, :!ls to get a listing of your directory.
另存为TEST
:w TEST
Type v then move the cursor to highlight the expected rows then :w TEST to save the selected rows to the new made file.
复合命令
:r TEST reads the content of the file and puts it below the cursor.
:r !ls reads the output of the ls command and puts it below the cursor.
Vi中的模式
Type a capital R to go into Replace mode and then Press <ESC> to leave
Replace mode.
替换模式
Type v to go into
可视模式, 可以通过移动光标选中要操作的内容。
Ctrl+v也会进入可视模式,但是不同于v或V进入的可视模式,可以自己查看一下。
Type i... to go into
插入模式
Type Esc to go into
命令模式
Move Faster
number + h/j/k/l can move the cursor faster.
搜索中的一些选项设置
Set the 'ic' (Ignore case) option by entering: :set ic
Set the 'hlsearch' and 'incsearch' options: :set hls is
To disable ignoring case enter :set noic
‘hls’ means highlight all the words searched. 高亮显示搜索结果
‘ic’ means ignore case,忽略大小写
‘is’ means incsearch, 加强搜索,输入搜索内容的时候光标自动跳到第一个符合搜索的内容。
取消设置只需要在前面加一个no就行,如noic是取消忽略大小写的设置。
移动显示内容
zz 将当前行显示在屏幕中间
zt 将当前行显示在屏幕顶端(top)
zb 底端(bottom)
光标不动,所在行向上移ctrl-e,向下的话ctrl-y~