美文网首页
vim配置文件模版

vim配置文件模版

作者: theache | 来源:发表于2020-05-21 12:32 被阅读0次

vim函数实现


function AddTitle()
call setline(1,"<?php")
call append(1,"")
call append(2,"/*")
call append(3," * Created by vim")
call append(4," * User: ache")
call append(5," * Date:" . strftime("%Y-%m-%d"))
call append(6," * Time:" . strftime("%H-%i"))
call append(7," * Describe:")
call append(8," */")
call append(9,"")
endf

# 新建文件时自动写入
autocmd BufNewFile *.php exec ":call AddTitle()"

# 新建文件后快捷键写入
nmap <leader>at :call AddTitle()<CR>

新建test.php即可看到以下内容

<?php

/**
 * Created by Vim.
 * User: ache
 * Date: 2020/5/21
 * Time: 11:26
 * Describe:
 */


或者使用第二种方式生成

vim插件实现

这里使用coc-template实现。
先安装coc.nvimgithub地址coc.nvim安装

安装coc-template

// 安装coc-templete命令
npm i coc-template

// vim下安装coc-templete插件
:CocInstall coc-template

查看插件所在的项目目录我本地是~/.config/coc/extensions/node_modules/coc-template。以下目录结构

.
├── README.md
├── lib
│   └── index.js
├── package.json
└── templates
    ├── =template=.bash
    ├── =template=.c
    ├── =template=.cmake
    ├── =template=.coffee
    ├── =template=.css
    ├── =template=.dart
    ├── =template=.f
    ├── =template=.f90
    ├── =template=.go
    ├── =template=.h
    ├── =template=.hs
    ├── =template=.html
    ├── =template=.humans.txt
    ├── =template=.java
    ├── =template=.jl
    ├── =template=.js
    ├── =template=.jsp
    ├── =template=.jsx
    ├── =template=.lhs
    ├── =template=.lua
    ├── =template=.ml
    ├── =template=.php
    ├── =template=.pl
    ├── =template=.pls
    ├── =template=.pm
    ├── =template=.pro
    ├── =template=.py
    ├── =template=.rb
    ├── =template=.robots.txt
    ├── =template=.rs
    ├── =template=.sh
    ├── =template=.sol
    ├── =template=.sql
    ├── =template=.tex
    ├── =template=.txt
    ├── =template=.xml
    ├── =template=.xsl
    ├── =template=.zcml
    └── =template=Makefile

templates文件夹下是模版文件可以根据需要自行修改添加。lib是脚本文件。可以在里面查看预定义的变量。修改=template=.php文件

<?php

/**
 * Created by Vim.
 * User: %USER%
 * Date: %YEAR%/%MONTH%/%DAY%
 * Time: %TIME%
 * Describe:
 */

%HERE%

%USER%等变量可在/lib/index.js里面查看定义

nmap <leader>t :CocCommand template.templateTop<CR>

新建test.php文件 使用<leader>t快捷键效果可上面的是一样的

相关文章

  • vim配置文件模版

    vim函数实现 新建test.php即可看到以下内容 或者使用第二种方式生成 vim插件实现 这里使用coc-te...

  • 在vim中使用模版文件

    在vim中使用模版文件 vim 中模版或框架,能让你在创建新的特定扩展名的文件时使用相对应的模版。 内容列表 在v...

  • vim中的.vimrc

    默认的配置文件 安装vim 之后,默认只会有 $ vim ~/.viminfo, 是没有 $ vim ~/.vim...

  • VIM显示行号以及各种配置文件

    1、在unbutu中vim的配置文件存放在/etc/vim目录中,配置文件名为vimrc 2、显示行号 进入vim...

  • vim c++ 代码自动格式化配置

    安装 vim 插件 auto-format 安装 Artistic Style 配置 vim 配置文件 .vim...

  • leoatchina的修改后的spf13-vim配置

    leoatchina的vim配置文件 This is leoatchina's vim config forked...

  • vim设置修改及命令

    修改vim环境 打开vim的配置文件:sudo vim /etc/vim/vimr #光标移动至文件末端,添加一新...

  • vim学习笔记

    vim 配置文件 在vim启动过程中,首先将查找配置文件并执行其中的命令,配置文件有三类 vimrc gvimrc...

  • 改变vim中tab的长度

    打开vim配置文件(比如sudo,或su进入root模式) 1.sudo vim /etc/vim/vimrc 添...

  • vim简单操作与配置

    vim 编辑器之神Emacs 神的编辑器 vim配置 ~/.vimrc 配置文件 vimplugin 管理vim插...

网友评论

      本文标题:vim配置文件模版

      本文链接:https://www.haomeiwen.com/subject/uhszohtx.html