侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130559 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

vimrc配置,新建文件时自动生成文件头

2023-12-19 星期二 / 0 评论 / 0 点赞 / 69 阅读 / 4500 字

vimrc配置-新建文件时自动生成文件头 以下代码加在home目录用户名文件下的.vimrc文件中。 " auto add file header

 vimrc配置-新建文件时自动生成文件头

以下代码加在home目录用户名文件下的.vimrc文件中。

 

" auto add file header

 

autocmd BufNewFile *.py 0r /home/user/.vim/vim_template/vim_header_for_python

 

autocmd BufNewFile *.py ks|call FileName()|'s

 

autocmd BufNewFile *.py ks|call CreatedTime()|'s

 

 

 

autocmd BufNewFile *.sh 0r /home/user/.vim/vim_template/vim_header_for_sh

 

autocmd BufNewFile *.sh ks|call FileName()|'s

 

autocmd BufNewFile *.sh ks|call CreatedTime()|'s

 

 

 

fun FileName()

 

    if line("$") > 10

 

        let l = 10

 

    else

 

        let l = line("$")

 

    endif

 

    exe "1," . l . "g/File Name:.*/s/File Name:.*/File Name: " .expand("%")

 

endfun

 

 

 

fun CreatedTime()

 

    if line("$") > 10

 

        let l = 10

 

    else

 

        let l = line("$")

 

    endif

 

    exe "1," . l . "g/Created Time:.*/s/Created Time:.*/Created Time: " .strftime("%Y-%m-%d %T")

 

endfun

 

" end auto add file header

新建两个文件,分别将生成的文件头格式:输入进去。

~/.vim/vim_template/vim_header_for_python文件内容:#!/usr/bin/python# -*- coding: utf-8 -*-########################################################################## File Name:# Author: Jhenxu# mail: [email protected]# Created Time:#########################################################################~/.vim/vim_template/vim_header_for_sh文件内容:########################################################################## File Name:# Author: Jhenxu# mail: [email protected]# Created Time:##########################################################################!/bin/bash

广告 广告

评论区