【问题标题】:How to Insert date in newly created file inside vim?如何在vim中新创建的文件中插入日期?
【发布时间】:2020-04-25 04:08:23
【问题描述】:

我是 vim 的新手,不知道该寻找什么。这就是我问这个问题的原因。

我搜索了互联网,发现它可以为特定文件名创建一个骨架文件。我有一个如下所示的文件:

/**
 *  author: 
 *  created: 
**/

有没有办法在创建新文件时自动执行如下操作。

/**
 *  author: mahfuzz
 *  created: 21.04.2020
**/

【问题讨论】:

标签: datetime vim


【解决方案1】:

实际上可以有某种动态模板 见here

~/.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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 2017-12-19
    • 1970-01-01
    相关资源
    最近更新 更多