上一个问题中有人建议将以下内容添加到VIM中:
nmap <F3> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
imap <F3> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR>
我想通过执行函数来插入时间戳,而不是使用F3。例如,输入:Now。
不幸的是,我没有查看VIM脚本。有人可以帮忙吗?
答案 0 :(得分:4)
:Now
不是一个函数,它是一个命令。您可以使用以下代码从第一个映射创建命令:
command -nargs=0 -bar Now execute "normal! a\<C-R>=strftime(\"%Y-%m-%d %a %I:%M %p\")\<CR>"
答案 1 :(得分:1)
" if not has 'Last Change' in first 5 lines
fun! InsertChangeLog()
let l:flag=0
for i in range(1,5)
if getline(i) !~ '.*Last Change.*'
let l:flag = l:flag + 1
endif
endfor
if l:flag >= 5
normal(1G)
call append(0, "File: <+Description+>")
call append(1, "Created: " . strftime("%a %d/%b/%Y hs %H:%M"))
call append(2, "Last Change: " . strftime("%a %d/%b/%Y hs %H:%M"))
call append(3, "author: <+digite seu nome+>")
call append(4, "site: <+your website+>")
call append(5, "twitter: <+your twitter here+>")
normal gg
endif
endfun
" map F4 to insert change log
map <special> <F4> <esc>:call InsertChangeLog()<cr>
" update changefile log
" http://tech.groups.yahoo.com/group/vim/message/51005
" automaticaly update Last Change whitout change jump list
" see :h keepjumps
fun! LastChange()
let _s=@/
let l = line(".")
let c = col(".")
if line("$") >= 5
1,5s/\s*Last Change:\s*\zs.*/\="" . strftime("%Y %b %d %X")/ge
endif
let @/=_s
call cursor(l, c)
endfun
autocmd BufWritePre * keepjumps call LastChange()
" place holders snippets - change map !!!
" File Templates
" --------------
" <leader>j jumps to the next marker
" iabbr <buffer> for for <+i+> in <+intervalo+>:<cr><tab><+i+>
function! LoadFileTemplate()
"silent! 0r ~/.vim/templates/%:e.tmpl
syn match vimTemplateMarker "<+.\++>" containedin=ALL
hi vimTemplateMarker guifg=#67a42c guibg=#112300 gui=bold
endfunction
function! JumpToNextPlaceholder()
let old_query = getreg('/')
echo search("<+.\\++>")
exec "norm! c/+>/e\<CR>"
call setreg('/', old_query)
endfunction
autocmd BufNewFile * :call LoadFileTemplate()
nnoremap <leader>j :call JumpToNextPlaceholder()<CR>a
inoremap <leader>j <ESC>:call JumpToNextPlaceholder()<CR>a