vim

vim config files
git clone https://git.bracken.jp/vim.git
Log | Files | Refs | LICENSE

snippets.vim (737B)


      1 " Code snippets
      2 
      3 " Insert the current date in '2020-04-22 (Thu)' format.
      4 nnoremap <Leader>cd i<C-R>=CurrentDate()<CR><Esc>
      5 
      6 " Returns the current date in YYYY-mm-dd form.
      7 " When in a file whose name is of the form YYYY-mm-dd, use that date instead.
      8 " This is useful for headings in VimWiki entries.
      9 function! CurrentDate()
     10   " Get the filename without path or extension.
     11   let fname = expand('%:t:r')
     12   if fname =~ '\d\d\d\d-\d\d-\d\d'
     13     let fdate = strptime('%Y-%m-%d', fname)
     14     return strftime('%Y-%m-%d (%a)', fdate)
     15   else
     16     return strftime('%Y-%m-%d (%a)')
     17   endif
     18 endfunc
     19 
     20 
     21 " Inject a boilerplate C/C++/Obj-C main() function.
     22 au FileType c,cpp,objc nmap <leader>cm iint main(int argc, char** argv) {<CR>return 0;<CR>}<ESC>%0