自动给VIM添加python头文件

用vim新建一个python文件后,如pw.py,会自动填写文件头部,如:

  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 # Pw @ 2013-04-15 17:26:33

将以下代码加入/etc/vim/vimrc文件:

function HeaderPython()
    call setline(1, "#!/usr/bin/env python")
    call append(1, "# -*- coding: utf-8 -*-")
    call append(2, "# Pw @ " . strftime('%Y-%m-%d %T', localtime()))
    normal G
    normal o
    normal o
endf

autocmd bufnewfile *.py call HeaderPython()



 

`.` 重复的是“上次编辑操作”(the last change, `:h .` repeat.txt)。

posted @ 2017-09-14 14:08  sjfgod  阅读(1150)  评论(0编辑  收藏  举报