[vim笔记]

1.实现多文件替换:

  [:argc *.cpp]

  [:argdo %s/Kenfly//g | update]

  [:s/p1/p2/g ]:将当前行中所有p1均用p2替代
  [:n1,n2s/p1/p2/g ]:将第n1至n2行中所有p1均用p2替代

2.实现多文件查找:

  [:args *.cpp]

  [:argdo /word]

3.重载文件:

  [:e!]

4.打开多文牛:

  1):  在终端输入:[$vim file1 file2..]

      文件间切换:[:bn]   下一个文件  [:bp]  上一个文件

      或按#后再按ctrl+shift+^ (#是数字,代表文件,按file顺序)

  2):  在vim输入: [:vs(sp) file]

     文件间切换: Ctrl+w 

5.快捷键的设置

  1): 注释一行: [map = I//<ESC>] 取消:[map - ^xx]

6.寄存器:

  ["?yy] :将当前行存放到?

  ["?p]  :取出?内容复制到当前光标处

7.自定义高亮显示

  "关键字高亮

    syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2

    syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1

    hi cFunction gui=none guifg=#1875CD

  "自定义高亮关键字

    syn keyword cType       uint uchar

  "符号&运算符高亮

    syn match       cLogicalOperator  display "[!<>]=\="

    syn match cbracket   display"[{}()]"

    syn match       cMathOperator     display "[-+\*%=,;]"

    syn match       cBinaryOperator   display "\(&\||\|\^\|<<\|>>\)=\="

    syn match       cLogicalOperator  display "&&\|||"

    syn match       cLogicalOperatorError display "\(&&\|||\)="

    hi clogicalOperator gui=none guifg=#5875AD

    hi cbracket gui=none guifg=#B218C1http://www.cnblogs.com/Kenfly/admin/EditPosts.aspx?postid=1884339

    hi cMathOperator gui=none guifg=#CD9225http://www.cnblogs.com/Kenfly/admin/EditPosts.aspx?postid=1884339

    hi cBinaryOperator gui=none guifg=#287525

    hi cLogicalOperatorError gui=none guifg=#78A525 guibg=#C00000 

 

8.windows与linux之间的文件格式转换

  windows默认的是用GBK编码,linux用的是UTF-8,转换很简单,只要两条命令:

    set fileformat=dos 或 set fileformat=unix

    set fileencoding=utf-8 或 set fileencoding=gb2312

9.快速代码对齐

  方法一:
    命令模式下:=:1,$
  方法二:
    gg(把关标定位到最上面),V(进入VISUAL模式),shift+g(选中整篇文本),然后=。
  方法三:
    gg=G

 10.光标位置书签 

  m[a-z]记录当前当标位置

       `[a-z]跳到记录的位置

posted on 2010-11-22 14:28  Kenfly  阅读(337)  评论(0编辑  收藏  举报