datetime - 如何在vim中新创建的文件中插入日期?
问题描述
我是 vim 的新手,我不知道要寻找什么。这就是我问这个问题的原因。
我搜索了互联网,发现它可以为特定文件名创建一个骨架文件。我有一个如下所示的文件:
/**
* author:
* created:
**/
创建新文件时,有什么方法可以自动执行以下操作。
/**
* author: mahfuzz
* created: 21.04.2020
**/
解决方案
实际上,可以在这里看到某种动态模板
在~/.config/nvim/after
我有一个名为ultisnips_custom.vim
" File: ultisnips_custom.vim - Custom UltiSnips settings
" Maintainer: Sergio Araújo
" Oririnal Creator: Noah Frederick
" Last Change: abr 16, 2020 - 14:50
" Place it at: after/plugin/ultisnips_custom.vim
" We need python or python3 to run ultisnips
if !has("python") && !has("python3")
finish
endif
" This function is called by the autocommand at the end of the file
function! TestAndLoadSkel() abort
let filename = expand('%')
" Abort on non-empty buffer or extant file
if !(line('$') == 1 && getline('$') == '') || filereadable('%')
return
endif
" Load UltiSnips in case it was deferred via vim-plug
if !exists('g:did_plugin_ultisnips') && exists(':PlugStatus')
call plug#load('ultisnips')
doautocmd FileType
endif
" the function feedkys simulates the insert key sequence in order to call
" the template (skel)
execute 'call feedkeys("i_skel\<C-r>=UltiSnips#ExpandSnippet()\<CR>")'
endfunction
augroup ultisnips_custom
autocmd!
au Bufnewfile *.sh,*.zsh,*.html,*.css,*.py,*.tex,*.md,*.vim :call TestAndLoadSkel()
augroup END
" vim: fdm=marker:sw=2:sts=2:et
推荐阅读
- java - 从 Angular 6 Httpclient 进行后期调用时,Java HttpServletRequest 参数为空
- linux - shm_open 是否提交固定数量的物理内存?
- python - 如何将 bs4.element.Tag 转换为 JSON 字典?
- php - 斜线和 wp_register_style
- javascript - 嵌套的 Javascript 如何返回“传递”承诺?
- c# - 有什么方法可以防止使用新 csproj 格式的 .NET 应用程序存在于 bin/debug/net472/AppName 中?
- powershell - 在 VSCode 的 PowerShell 命令提示符中隐藏完整文件路径
- python - 在 django 中加载图像时的可疑操作
- vue.js - Webpack:为什么 vue-loader 不能转译?
- javascript - 使用 Formdata React Native 将图像上传到 Firebase