Как вставить дату во вновь созданный файл внутри vim? - PullRequest
0 голосов
/ 25 апреля 2020

Я новичок в vim и не знаю, что искать. Вот почему я задаю этот вопрос.

Я искал inte rnet и нашел его для создания файла скелета для указанного c имени файла. У меня есть файл, который выглядит следующим образом:

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

Есть ли способ автоматически сделать что-то вроде ниже при создании нового файла.

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

1 Ответ

1 голос
/ 25 апреля 2020

На самом деле возможно иметь какие-то шаблоны c, см. здесь

На ~/.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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...