V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
cuijiudai
V2EX  ›  Vim

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

  •  
  •   cuijiudai · Sep 10, 2013 · 6694 views
    This topic created in 4612 days ago, the information mentioned may be changed or developed.
    vim 创建py 文件的能不能第一行自动添加这一句:

    #-*- encoding:utf-8 -*-
    10 replies    1970-01-01 08:00:00 +08:00
    kumu
        1
    kumu  
       Sep 10, 2013   ❤️ 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  
       Sep 10, 2013
    @kumu 配置文件为~/.vimrc
    xiaokai
        3
    xiaokai  
       Sep 10, 2013   ❤️ 1
    我一般这样

    autocmd BufNewFile *.php 0r $VIMFILES/template/template.py
    xiaokai
        4
    xiaokai  
       Sep 10, 2013   ❤️ 1
    - - 刚才后缀没改完。。。

    autocmd BufNewFile *.py 0r $VIMFILES/template/template.py
    mengzhuo
        5
    mengzhuo  
       Sep 10, 2013
    eth2net
        6
    eth2net  
       Sep 10, 2013
    wklken
        8
    wklken  
       Sep 10, 2013
    syv2
        9
    syv2  
       Sep 10, 2013
    在.vimrc里添加一行
    autocmd BufNewFile *.py 0r /path_to_template_file
    GreenHand
        10
    GreenHand  
       Sep 11, 2013
    autocmd BufNewFile *.py 0r ~/.python_template.py
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   989 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 19:11 · PVG 03:11 · LAX 12:11 · JFK 15:11
    ♥ Do have faith in what you're doing.