funcs.vim (2809B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | " " author : Xu Xiaodong <[email protected]> " modified : 2016 Dec 04 " "-- update timestamps --" function! _last_modified() if &modified let save_cursor = getpos(".") let n = min([20, line("$")]) keepjumps exe '1,' . n . 's#^\(.\{,10}modified *: \+\).*#\1' . \ strftime('%Y %b %d') . '#ei' call histdel('search', -1) call setpos('.', save_cursor) endif endfunction "-- set modeline --" function! _set_modeline() let filetype = input("Please enter file type: ", expand('<cword>')) exe "normal i# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=" . filetype endfunction "-- add perl 'use' statement --" " make sure you have " setlocal iskeyword=48-57,_,A-Z,a-z,: " so colons are recognized as part of a keyword function! _perl_use() let s:package = input('Package? ', expand('<cword>')) " skip if that use statement already exists if (search('^use\s\+'.s:package, 'bnw') == 0) " below the last use statement, except for some special cases let s:line = search('^use\s\+\(constant\|strict\|warnings\|parent\|base\|5\)\@!','bnw') " otherwise, below the ABSTRACT (see Dist::Zilla) if (s:line == 0) let s:line = search('^# ABSTRACT','bnw') endif " otherwise, below the package statement if (s:line == 0) let s:line = search('^package\s\+','bnw') endif " if there isn't a package statement either, put it below " the last use statement, no matter what it is if (s:line == 0) let s:line = search('^use\s\+','bnw') endif " if there are no package or use statements, it might be a " script; put it below the shebang line if (s:line == 0) let s:line = search('^#!','bnw') endif " if s:line still is 0, it just goes at the top call append(s:line, 'use ' . s:package . ';') endif endfunction "-- perl comment --" function! _perl_comment() let l = getline('.') if l =~ '^#' exe 's/^#//g' else exe 's/^/#/g' endif endfunction "-- markdown header --" function! _markdown_header() let date = strftime("%Y-%m-%d %T") exe "normal iTitle: " exe "normal oDate: " . date exe "normal oAuthors: toy" exe "normal oCategory: News" exe "normal oTags: " exe "normal oSlug: " exe "normal oVia: " exe "normal o" endfunction "-- add script header --" function! _set_sh_header() let filetype = input("File type: ", expand('<cword>')) let filename = bufname("%") let date = strftime("%Y %b %d") if (filetype != '') exe "normal i#!/usr/bin/env " . filetype exe "normal o#" else exe "normal i#" endif exe "normal o# name : " . filename exe "normal o# author : Xu Xiaodong <[email protected]>" exe "normal o# license : GPLv3" exe "normal o# created : " . date exe "normal o# modified : " . date exe "normal o#" exe "normal o" endfunction |