V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cuijiudai
V2EX  ›  Vim

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

  •  
  •   cuijiudai · 2013-09-10 16:44:40 +08:00 · 5824 次点击
    这是一个创建于 3880 天前的主题,其中的信息可能已经有所发展或是发生改变。
    vim 创建py 文件的能不能第一行自动添加这一句:

    #-*- encoding:utf-8 -*-
    10 条回复    1970-01-01 08:00:00 +08:00
    kumu
        1
    kumu  
       2013-09-10 17:11:52 +08:00   ❤️ 1
    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
        2
    kumu  
       2013-09-10 17:12:29 +08:00
    @kumu 配置文件为~/.vimrc
    xiaokai
        3
    xiaokai  
       2013-09-10 17:30:51 +08:00   ❤️ 1
    我一般这样

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

    autocmd BufNewFile *.py 0r $VIMFILES/template/template.py
    mengzhuo
        5
    mengzhuo  
       2013-09-10 17:36:57 +08:00
    eth2net
        6
    eth2net  
       2013-09-10 17:59:41 +08:00
    jpuyy
        7
    jpuyy  
       2013-09-10 20:20:25 +08:00
    wklken
        8
    wklken  
       2013-09-10 22:19:38 +08:00
    syv2
        9
    syv2  
       2013-09-10 22:56:48 +08:00
    在.vimrc里添加一行
    autocmd BufNewFile *.py 0r /path_to_template_file
    GreenHand
        10
    GreenHand  
       2013-09-11 00:26:56 +08:00
    autocmd BufNewFile *.py 0r ~/.python_template.py
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3274 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:16 · PVG 21:16 · LAX 06:16 · JFK 09:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.