cuijiudai
V2EX  ›  Vim

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

  •  
  •   cuijiudai · Sep 10, 2013 · 7223 views
    This topic created in 4808 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
    kumu
    Sep 10, 2013❤️1
    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
    kumu
    Sep 10, 2013
    2
    @kumu 配置文件为~/.vimrc
    xiaokai
    xiaokai
    Sep 10, 2013❤️1
    3
    我一般这样

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

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