vim是一个多模式的编辑器。就目前来看,主要有以下几个主要模式。
--NORMAL--
通常模式(n) 在其它任何一个模式下,用ESC或者 ctrl+c 键可以退到通常模式
--INSERT--
插入模式(i) 在这个模式下,vim像一个常见的编辑器.在通常模式下,用i或者a可以进行本模式,当然,还有一些其它命令也可以.
--VISIUAL--
可视模式(v) 在这个模式下,可以使用hjkl进行选择.然后进行copy,paste或者其它操作. 在通常模式下,用v命令进行可视模式.
--VISIUAL BLOCK--
块操作模式(V) 这是块操作模式. 在通常模式下,用ctrl+v进入本模式.
--VISIUAL LINE--
行操作模式(V) 这是块操作模式. 在通常模式下,用shift+v进入本模式.
5. 修改模式(R) 这是改写的模式.很多软件法用insert键来完成这个切换.在vim中,从通常模式用R即可进入改写模式.
EX扩展命令模式
扩展命令模式(ex) 这是命令执行模式 在通常模式下用:切换到此模式.
===如何快速格式化
格式化全文指令 gg=G
自动缩进当前行指令 ==
格式化当前光标接下来的8行 8=
格式化选定的行 v 选中需要格式化的代码段 =
备注:
gg —— 到达文件最开始
= —— 要求缩进
G —— 直到文件尾
注释代码:(这个原理上就是使用VIM的正则替换)
===
我在window下,gvim启动时默认directory是vim的安装目录,因而无意中创建的文件就是那里,如何进行改变呢。
以下是方法。
Assuming you're starting gvim from an icon/shortcut in Windows (from the kind of paths you supply), you can change the starting directory (completely independent from the fact that it IS gvim: it would be the same from any other app!) by editing the "starting directory" property of that Windows icon/shortcut.
======
如何在vim中迅速进行复制呢?
The Ex way:
:t.
will duplicate the line,:t 7
will copy it after line 7,:,+t0
will copy current and next line at the beginning of the file (,+
is a synonym for the range.,.+1
),:1,t$
will copy lines from beginning till cursor position to the end (1,
is a synonym for the range1,.
).
If you need to move instead of copying, use :m
instead of :t
.
This can be really powerful if you combine it with :g
or :v
:
:v/foo/m$
will move all lines not matching the pattern “foo” to the end of the file.:+,$g/^\s*class\s\+\i\+/t.
will copy all subsequent lines of the formclass xxx
right after the cursor.
Reference: :help range
, :help :t
, :help :g
,:help :m
and:help :v
t是指在vim 当前tab中进行复制
m是指move,也是指在当前tab中
d是指del
y是指yank
这些都可以用这些方法进行。而不必要进入visual mode, 效率之高令人赞叹!
emmet.vim的使用注意事项
Type abbreviation
+-------------------------------------
| html:5_
+-------------------------------------
"_" is a cursor position. and type "<c-y>," (Ctrl + y and Comma)
NOTE: Don't worry about key map. you can change it easily.
+-------------------------------------
| <!DOCTYPE HTML>
| <html lang="en">
| <head>
| <title></title>
| <meta charset="UTF-8">
| </head>
| <body>
| _
| </body>
| </html>
+-------------------------------------
Type following
+-------------------------------------
| div#foo$*2>div.bar
+-------------------------------------
And type "<c-y>,"
+-------------------------------------
|<div id="foo1">
| <div class="bar">_</div>
|</div>
|<div id="foo2">
| <div class="bar"></div>
|</div>
| _
+-------------------------------------
vim的一些使用技巧
rangeshttp://vim.wikia.com/wiki/Ranges