- Screen Scroll
- Cursor Locating
- Insert
- Delete, Modify, Paste
- Cursor Moving
- Search
- Replace
- Visual Mode
- Misc
- Text-Object
- Plugins Related
CTRL-E N CTRL-E 窗口下滚 N 行 (缺省: 1) (Extra)
CTRL-D N CTRL-D 窗口下滚 N 行 (缺省: 1/2 窗口) (Downwards)
CTRL-F N CTRL-F 窗口下滚 N 页 (Forwards)
CTRL-Y N CTRL-Y 窗口上滚 N 行 (缺省: 1)
CTRL-U N CTRL-U 窗口上滚 N 行 (缺省: 1/2 窗口) (Upwards)
CTRL-B N CTRL-B 窗口上滚 N 页 (Backwards)
z z 或 zt 重画,当前行置窗口顶端
z. z. 或 zz 重画,当前行置窗口正中
z- z- 或 zb 重画,当前行置窗口底端
ZZ 如果文件被修改,写回当前文件。然后退出。(和 :x 相
同)。(注意: 如果有当前文件有多个窗口,该文件在被修改
时会被写回,当前窗口会被关闭)。
a N a 在光标后添加文本 (N 次) aka:append
A N A 在行末添加文本 (N 次)
i N i 在光标前插入文本 (N 次) (亦: )
I N I 在当前行的第一个非空白字符前插入文本 (N 次)
gI N gI 在第一栏中插入文本 (N 次)
o N o 在当前行下方开始新行,添加文本 (N 次)
O N O 在当前行上方开始新行,添加文本 (N 次)
d N d{motion} 删除动作 {motion} 覆盖的文本
dd N dd 删除 N 行
D N D 删除至行尾 (及 N - 1 后续行)
c N c{motion} 修改动作 {motion} 覆盖的文本,需要跟一个动作指令,如h、j、k、l,删除后进入编辑模式
C N C 修改至行尾 (及 N - 1 后续行)
cc N cc 修改 N 行
s N s 修改 N 个字符,删除光标字符后直接进入编辑模式
S N S 修改 N 行
r N r{char} 以 {char} 替换 N 个字符,但是不进入编辑模式
y N y{motion} 将动作 {motion} 覆盖的文本抽出至一个寄存器
v_y {visual}y 将高亮的文本抽出至一个寄存器
yy N yy 抽出 N 行至寄存器
Y N Y 抽出 N 行至寄存器
w N w 向前 (正向,下同) N 个单词 (word)
W N W 向前 N 个空白隔开的字串 WORD (WORD)
e N e 向前至第 N 个单词词尾 (end)
E N E 向前至第 N 个空白隔开的字串 WORD 的词尾 (End)
b N b 向后 (反向,下同) N 个单词 (backward)
B N B 向后至第 N 个空白隔开的字串 WORD 的词尾 (Backward)
gk N gk 上移 N 屏幕行 (回绕行时不同于 "k")
gj N gj 下移 N 屏幕行 (回绕行时不同于 "j")
H N H 至窗口的第 N 行的第一个非空白字符处 (Home)
M M 至窗口的中间行的第一个非空白字符处 (Middle)
L N L 至窗口的第 N 行 (从下方算) 的第一个非空白字符处 (Last)
CTRL-O 转到跳转表里第 [count] 个较旧的光标位置(不是动作命令)。
或 CTRL-I 转到跳转表里第 [count] 个较新的光标位置(不是动作命令)。
`` `` 至上次跳转之前的位置
g; 转到改变表里第 [count] 个较旧的位置。(不是动作命令)
g, 转到改变表里第 [count] 个较新的位置。和 g; 类似,但朝向相反的方向。(不是动作命令)
) N ) 向前 N 个句子
( N ( 向后 N 个句子
} N } 向前 N 个段落
{ N { 向后 N 个段落
f N f{char} 至右边第 N 次出现 {char} 之处 (find)
F N F{char} 至左边第 N 次出现 {char} 之处 (Find)
; N ; 重复上次 "f"、"F"、"t" 或 "T" 命令 N 次
, N , 以相反方向重复上次 "f"、"F"、"t" 或 "T" 命令 N 次
star N * 向前查找光标下的标识符
默认是区分大小写的, 如果要不区分大小写, 那么如下设置:
:set ignorecase
或简写成
:set ic
后再发送查询指令.
或者在查找指令后加\c标志, 如:
/search-text\c
如果返回默认区分大小写, 那么如下设置:
:set noignorecase
或简写成
:set noic
后再发送查询指令.
# N # 向后查找光标下的标识符
n N n 重复上次查找
N N N 相反方向重复上次查找
:nohlsearch :noh[lsearch] 暂停 'hlsearch' 高亮
替换命令可以在全文中用一个单词替换另一个单词:
:%s/four/4/g"%" 范围前缀表示在所有行中执行替换。最后的 "g" 标记表示替换行中的所有匹配点。 如果你有一个像 "thirtyfour" 这样的单词,上面的命令会出错。这种情况下,这 个单词会被替换成 "thirty4"。要解决这个问题,用 "<" 来指定匹配单词开头:
:%s/\<four/4/g显然,这样在处理 "fourteen" 的时候还是会出错。用 ">" 来解决这个问题:
:%s/\<four\>/4/g如果你在编码,你可能只想替换注释中的 "four",而保留代码中的。由于这很难指定, 可以在替换命令中加一个 "c" 标记,这样,Vim 会在每次替换前提示你:
:%s/\<four\>/4/gcOther examples:
去掉第3行到最后一行的**
:3,$s/\*\*//g$ cat insert-space.vim
%s/\([0-9a-zA-Z]\)\([\u4e00-\u9fff]\)/\1 \2/g
%s/\([\u4e00-\u9fff]\)\([0-9a-zA-Z]\)/\1 \2/g
writev v 开始面向字符的可视 (Visual) 模式
V V 进入面向行的可视 (Visual) 模式
CTRL-V CTRL-V 开始面向列块的可视 (Visual) 模式
gv gv 重新选择上次的可视区域
. N . 重复最近一次改动 (但计数改为 N)
~ ~ 2 'tildeop' 关闭时: 切换光标所在处开始的 N 个
字符的大小写,并右移光标 N 个字符
~ ~{motion} 'tildeop' 打开时: 切换 Nmove 文本的大小写
< <{motion} 2 左移 Nmove 文本行一个 'shiftwidth'
<< << 2 左移 N 行一个 'shiftwidth'
= ={motion} 2 通过 "indent" 过滤 Nmove 文本行
== == 2 通过 "indent" 过滤 N 行
> >{motion} 2 右移 Nmove 文本行一个 'shiftwidth'
>> >> 2 右移 N 行一个 'shiftwidth'
Text-Object:可以指一个单词,一整句文本,抑或一对括号内的文本,甚至是html或xml标签内的文本,都可以抽象成Text-Object。与Text-Object紧密相关的两个命令就是a和i,啊?这两个命令不是append和insert吗?其实,a和i操作在Visual mode或者某些操作(比如:d,y等)后面就是另外一种效果了。例如,删除一个单词可以用daw或者diw。那么a与i又有什么区别呢?
** a会选择一个对象(an object)包括空格在内,而i只会选择一个对象的内部(an inner object)不包含空格。**
下面就是一些命令含义:
aw a word
iw inner word
aW a WORD
iW inner WORD
as a sentence
is inner sentence
ap a paragraph
ip inner paragraph
a[|] a[] block (这里的'|'是或的意思,也就是说'a['和'a]'都表示一个[]块)
'{} &al;>()与[]作用类似
at a tag (这里的tag可以是html或xml中任何标签对)
it inner tag
比如在一个html文件中,当前光标在某个标签对的内容里头的时候,命令dat会把整个标签对包括内容都会删除,而dit只会删除标签对之间的内容,保留标签对。详细说明可以:help text-objecgts
eg:
ciw diw viw yiw
<leader>-n to toggle Nerdtree.
Here are some frequently used commands:
| Command | Function |
|---|---|
m |
open the menu |
o or Enter |
open files, directories, bookmarks |
O |
Recursivly open the selected directory |
s |
open a file in a vertical split window |
i |
open a file in a horizontal split window |
t |
open a file in new tab |
x |
close the current node parent (unfold current folder) |
X |
Recursivly close the current node parent (unfold folders) |
R |
refresh |
| cd | change tree root to the selected node/directory |
| CD | change tree root to CWD |
I |
toggle whether hidden files displayed |
| f | toggle whether file filters are used |
| F | toggle whether files are displayed |
| B | toggle whether bookmark table displayed |
q |
QUIT nerdtree window |
| A | zoom in/out nerdtree window |
For complete usage instructions, see Nerdtree Official Doc
This allows you to select some text using Vim's visual mode and then hit * and # to search for it elsewhere in the file.
<leader>-m to open MRU.
You can press the 'o' key to open the file name under the cursor in the MRU window in a new window.
To open a file from the MRU window in read-only mode (view), press the 'v' key.
To open a file from the MRU window in a new tab, press the 't' key. If the file is already opened in a window in the current or in another tab, then the cursor is moved to that tab. Otherwise, a new tab is opened.
You can open multiple files from the MRU window by specifying a count before pressing '' or 'v' or 'o' or 't'. You can also visually select multiple filenames and invoke the commands to open the files. Each selected file will be opened in a separate window or tab.
You can press the 'u' key in the MRU window to update the file list. This is useful if you keep the MRU window open always.
You can close the MRU window by pressing the 'q' key or using one of the Vim window commands.
I modify the following source code to change the opening file keys to match with NERDTree.
" Create mappings to select and edit a file from the MRU list
nnoremap <buffer> <silent> o
\ :call <SID>MRU_Select_File_Cmd('edit,useopen')<CR>
vnoremap <buffer> <silent> o
\ :call <SID>MRU_Select_File_Cmd('edit,useopen')<CR>
nnoremap <buffer> <silent> i
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_horiz')<CR>
vnoremap <buffer> <silent> i
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_horiz')<CR>
nnoremap <buffer> <silent> <S-CR>
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_horiz')<CR>
vnoremap <buffer> <silent> <S-CR>
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_horiz')<CR>
nnoremap <buffer> <silent> s
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_vert')<CR>
vnoremap <buffer> <silent> s
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_vert')<CR>Now press 'o' to open the file in the whole window, 's' to open in a split horizontal window, 'i' to open in a split vertical window.
<leader>-t to open Tagbar.
The following mappings are valid in the Tagbar window:
<CR>/<Enter> Jump to the tag under the cursor. Doesn't work for pseudo-tags
or generic headers.
Map option: tagbar_map_jump
p Jump to the tag under the cursor, but stay in the Tagbar window.
Map option: tagbar_map_preview
P Open the tag in a |preview-window|.
Map option: tagbar_map_previewwin
o/za Toggle the fold under the cursor or the current one if there is
no fold under the cursor.
Map option: tagbar_map_togglefold
s Toggle sort order between name and file order.
Map option: tagbar_map_togglesort