首页 > 技术 > 强大的VIM技巧

强大的VIM技巧

  • 本文链接地址:http://zhubaining.com/blog/2009/05/27/archives/vim-technique
  • 作者:zhubaining

K: 查看关键字的man page,在可视模式它会以选中的文本为关键字。

da<      Delete the HTML tag the cursor is currently inside of – the whole tag, regardless of just where the cursor is.
ci"    -> Delete everything inside "" string and start insert mode
da[    -> Delete the [] region around your cursor
vi'    -> Visual select everything inside '' string
ya(    -> Yank all text from ( to )

control-A / control-X:跳到当前行的数字上,进行增1或者减1,居然可以支持C语言风格的八、十、十六进制。

. (period):Repeats the previous change

[I:list all lines found in current and included files that contain the word under the cursor.

Ctrl-c: quit Insert mode (faster than ESC)

Record:

q<some key>
<edit one line and move to the next>
q
Play:

@<some key>
@@ (play last macro)
100@<some key> (apply macro 100 times)

:%s//replace/g will replace the last term that was searched for, instead of you having to type it again. This works well with using * to search for the word under the cursor.

ctrl-x->ctrl-f (while cursor on a path string): searches for the path and auto-completes it, with multi-optional selection.  

Putting options in comments in a file to be edited. That way the specific options will follow the file. Example, from inside a script:
# vim: ts=3 sw=3 et sm ai smd sc bg=dark nohlsearch
% Brace/parentheses match. If you have the cursor on a parenthesis/brace/etc ((){}[]), and hit % it will jump to the corresponding one.

Read contents of an external command into the doc:   :r !ls

:g/search/p:Grep inside this file and print matching lines. You can also replace p with d to delete matching lines.

[[ - Beginning of the current function block.
]] - Beginning of the next funcion.
[{ - Beginning of the current code block.
]} - End of the current code block.

z - position the current line to the top of the screen.
zz - position the current line to the center of the screen.
z- - position the current line to the bottom of the screen.

H 光标移至屏幕顶行。
M 光标移至屏幕中间行。
L 光标移至屏幕最后行。

ZZ - Save & Exit

#: Search backwards in the file for the word under the cursor.  Useful for finding declarations.
%j: To join all lines into a single line.

查看ASCII码: ga         查看当前光标下的字符的ascii,十六进制,8进制
 # 另外,也可以‘man ascii’来查看ascii码表.

:%!xxd 按十六进制查看当前文件
:%!xxd -r 从十六进制返回正常模式 

:%!cat -n : 为文件内容增加行号

:r! command : 将命令 Command 的输出结果放到当前行。

d0 删至行首。
d$ 删至行尾。

:g/gladiolli/#    : 查找并显示匹配的行号

:%norm jdd    : 隔行删除

<C-X><C-L>    : 行自动完成(超级有用)

:Exp(lore)    : 浏览文件

:Sex(plore)    : 分割窗口浏览文件

guu    : 将整行的字母转换成小写

gUU    : 将整行的字母转换成大写

Vu    : 转换选中的行(小写)

VU    : 转换选中的行(大写)

<C-R>=5*5    : 插入25 (小型计算器) (插入模式下)

'.    : 跳回最后编辑的行 (超有用)

[I    : 显示当前行中字符的所有匹配(超级有用)

<C-X><C-F>    : 插入当前目录下的一个文件名到当前位置

▼在当前插入模式下编辑/移动 (真得很有用)

<C-U>    : 删除全部

gf    : 打开光标处广义字命名的文件 (normal模式)

:set ro (Read Only)    : 只读保护
<C-W>    : 删除最后一个单词

PHP函数自动补全:
下载函数名列表文件:http://cvs.php.net/viewvc.cgi/phpdoc/funclist.txt?revision=1.39&view=co
set dictionary-=~/.vim/funclist.txt dictionary+=~/.vim/funclist.txt
set complete-=k complete +=k

搜索:
  • 设置大小写不敏感:  :set ic ,取消: :set noic
  • 临时大小写不敏感搜索:  /\csomething
分类: 技术 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.