1. The cursor is moved using either the arrow keys or the hjkl keys.
h (left) j (down) k (up) l (right)# 上下左右移动2. To start Vim from the shell prompt type: vim FILENAME <ENTER># vim filename 打开文件3. To exit Vim type: <ESC> :q!<ENTER> to trash all changes.
OR type: <ESC> :wq <ENTER> to save the changes.
# :q!退出,:wq保存4. To delete the character at the cursor type: x
# x删除字符5. To insert or append text type:
i type inserted text <ESC> insert before the cursor
A type appended text <ESC> append after the line
# i插入,A行尾插入
lesson 2 SUMMARY
1. To delete from the cursor up to the next word type: dw
2. To delete from the cursor to the end of a line type: d$
3. To delete a whole line type: dd# 删除使用 d motion,dw删除字符,d$删除到行尾,dd删除一行4. To repeat a motion prepend it with a number: 2w # 移动两个字符5. The formatfor 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),
$ (to the end of line), etc.
6. To move to the start of the line use a zero: 0# 移动到行首7. 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 # undo重做
lesson 3 SUMMARY
1. To put back text that has just been deleted, type p . This puts the
deleted text AFTER the cursor (if a line was deleted it will go on the
line below the cursor).
# p把删除的东西再打印出来2. To replace the character under the cursor, type r and then the
character you want to have there.
# r替换字符3. The change operator allows you to change from the cursor to where the
motion takes you. eg. Type ce to change from the cursor to the end of
the word, c$ to change to the end of a line.
# c是修改,c$是删除光标到行尾的所有字符4. The formatfor change is:
# c可以后面跟数字,动作类型
c [number] motion
lesson 4 SUMMARY
1. CTRL-G displays your location in the file and the file status.
G moves to the end of the file.
number G moves to that line number.
gg moves to the first line.
# G移动到文件结尾, 数字 G 移动到某一行, gg移动到文件第一行2. Typing / followed by a phrase searches FORWARD for the phrase.
Typing ? followed by a phrase searches BACKWARD for the phrase.
After a search type n to find the next occurrence in the same direction
or N to search in the opposite direction.
CTRL-O takes you back to older positions, CTRL-I to newer positions.
# /是向后搜索,?号是向前搜索, n是下一项(向前搜就向前一项,向后搜就向后一项) N是上一项。# CTRL-O 是跳转到上一个光标的位置,CTRL-I是反操作3. Typing % while the cursor is on a (,),[,],{, or } goes to its match.
# %是跳转到对应的匹配,对应的括号来回跳,之前都不知道。这个太方便了。4. To substitute new for the first old in a line type :s/old/new
To substitute new for all 'old's on a line type :s/old/new/g
To substitute phrases between two line #'s type :#,#s/old/new/g
To substitute all occurrences in the filetype :%s/old/new/g
To ask for confirmation each timeadd'c' :%s/old/new/gc
# 字符替换:s/old/new替换当前行第一个,:s/old/new/g替换整行,:%s/old/new/g整个文件替换,:%s/old/new/gc整个文件替换并需要确认
lesson 5 SUMMARY
1. :!command executes an external command.
# 使用!命令 执行shell命令
Some useful examples are:
(MS-DOS)(Unix)
:!dir :!ls - shows a directory listing.
:!del FILENAME :!rm FILENAME - removes file FILENAME.
2. :w FILENAME writes the current Vim file to disk with name FILENAME.
# :w 文件名 会保存一个新的文件3. v motion :w FILENAME saves the Visually selected lines infile
FILENAME.
# v 动作 加上:w 文件名 会保存选中的内容到新文件里4. :r FILENAME retrieves disk file FILENAME and puts it below the
cursor position.
# :r 文件名 可以把文件中的数据读取出来写到光标的位置5. :r !dir reads the output of the dircommand and puts it below the
cursor position.
# :r !命令 可以把shell命令执行的结果写进文件里
lesson 6 SUMMARY
1. Type o to open a line BELOW the cursor and start Insert mode.
Type O to open a line ABOVE the cursor.
# 使用o向下新增一行,使用O向上新增一行2. Type a to insert text AFTER the cursor.
Type A to insert text after the end of the line.
# 使用a在光标后进入插入模式,使用A在text末尾进入插入模式3. The e command moves to the end of a word.
# 使用e命令移动到单词的尾部4. The y operator yanks (copies) text, p puts (pastes) it.
# 在visual模式下,使用y复制text,使用p粘贴5. Typing a capital R enters Replace mode until<ESC> is pressed.
# 使用R来实现进入替换模式,ESC来退出,每次替换都是替换已有的字符6. Typing ":set xxx" sets the option "xxx". Some options are:
'ic''ignorecase' ignore upper/lower case when searching
'is''incsearch' show partial matches for a search phrase
'hls''hlsearch' highlight all matching phrases
You can either use the long or the short option name.
# 使用:set xxx来执行设置一些选项,如ic是忽略大小写比较,is显示搜索短语的部分匹配项,hls搜索高亮7. Prepend "no" to switch an option off: :set noic
# 在:set xxx前增加no来关闭选项
lesson 7 SUMMARY
1. Type :help or press <F1> or <Help> to open a help window.
# 按F1寻求帮助2. Type :help cmd to findhelp on cmd .# 输入:help同样能打开帮助3. Type CTRL-W CTRL-W to jump to another window
# CTRL-W CTRL-W 可以在不同窗口跳转4. Type :q to close the help window
# :q 退出帮助窗口5. Create a vimrc startup script to keep your preferred settings.
# 可以创建一个vimrc的设置脚本在vim启动时,~/.vimrc6. When typing a : command, press CTRL-D to see possible completions.
Press <TAB> to use one completion.
# 在输入:x 收,输入CTRL-D查看所有可能的匹配参数,按TAB一个一个匹配
lesson 1 SUMMARY 1. The cursor is moved using either the arrow keys or the hjkl keys. h (left) j (down) k (up) l (right)# 上下左右移动 2. To start Vim from the shell prompt type: vim FILENAME <ENTER># vim filename 打开文件 3