vim 创建 py 文件如何添加默认内容

2013-09-10 16:44:40 +08:00
 cuijiudai
vim 创建py 文件的能不能第一行自动添加这一句:

#-*- encoding:utf-8 -*-
5837 次点击
所在节点    Vim
10 条回复
kumu
2013-09-10 17:11:52 +08:00
function HeaderPython()
call setline(1, "#!/usr/bin/env python")
call append(1, "# -*- coding: utf-8 -*-")
normal G
normal o
normal o
endf
autocmd bufnewfile *.py call HeaderPython()

加入以上代码即可
kumu
2013-09-10 17:12:29 +08:00
@kumu 配置文件为~/.vimrc
xiaokai
2013-09-10 17:30:51 +08:00
我一般这样

autocmd BufNewFile *.php 0r $VIMFILES/template/template.py
xiaokai
2013-09-10 17:32:37 +08:00
- - 刚才后缀没改完。。。

autocmd BufNewFile *.py 0r $VIMFILES/template/template.py
mengzhuo
2013-09-10 17:36:57 +08:00
eth2net
2013-09-10 17:59:41 +08:00
jpuyy
2013-09-10 20:20:25 +08:00
wklken
2013-09-10 22:19:38 +08:00
syv2
2013-09-10 22:56:48 +08:00
在.vimrc里添加一行
autocmd BufNewFile *.py 0r /path_to_template_file
GreenHand
2013-09-11 00:26:56 +08:00
autocmd BufNewFile *.py 0r ~/.python_template.py

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/81947

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX