Vim添加CPP/C头文件snappet

来源:互联网 发布:淘宝1元包邮怎么赚钱 编辑:程序博客网 时间:2024/05/21 01:48


原文:http://www.thegeekstuff.com/2008/12/vi-and-vim-autocommand-3-steps-to-add-custom-header-to-your-file/

正文:

1.首先创建一个header.txt文件内容:

:insert/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.* File Name :* Purpose :* Creation Date :* Last Modified :* Created By :  _._._._._._._._._._._._._._._._._._._._._.*/.

注意   点不能省略。不是错误。


2.在.vimrc中后添加 如下内容

autocmd bufnewfile *.c so /home/jsmith/c_header.txtautocmd bufnewfile *.c exe "1," . 10 . "g/File Name :.*/s//File Name : " .expand("%")autocmd bufnewfile *.c exe "1," . 10 . "g/Creation Date :.*/s//Creation Date : " .strftime("%d-%m-%Y")autocmd Bufwritepre,filewritepre *.c execute "normal ma"autocmd Bufwritepre,filewritepre *.c exe "1," . 10 . "g/Last Modified :.*/s/Last Modified :.*/Last Modified : " .strftime("%c")autocmd bufwritepost,filewritepost *.c execute "normal `a"



3.注意修改修改配置文件txt文件的路径。

4. 然后vim xxxx.c 文件试试。




另外:

  1. 第一行命令定义配置文件位置。
  2. 第二hang 搜索“File Name:” 在1-10行,如果发现,写到这行。
  3. 第三行,更新时间field
  4. 第五行,更新修改时间,保存时间
  5. 第4&6行,保存文件时,游标移到最后修改的位置。如果想回到之前位置,添加四到六行到.vimrc文件,
  6. 第4行,在更新位置之前保存当前位置。
  7. 第6行,恢复之前游标的位置到之前位置。



谢谢阅读。