这是我从中提取的代码vim-startify
;关键部分是在VimEnter
autocmd 上创建一个新缓冲区,在其中添加一些文本,然后映射i
来启动一个新缓冲区,然后进入插入模式。
我将下面的内容添加到一个小插件中,其中添加了一些设置等,但是基本概念是完全相同的。
fun! Start()
" Don't run if: we have commandline arguments, we don't have an empty
" buffer, if we've not invoked as vim or gvim, or if we'e start in insert mode
if argc() || line2byte('$') != -1 || v:progname !~? '^[-gmnq]\=vim\=x\=\%[\.exe]$' || &insertmode
return
endif
" Start a new buffer ...
enew
" ... and set some options for it
setlocal
\ bufhidden=wipe
\ buftype=nofile
\ nobuflisted
\ nocursorcolumn
\ nocursorline
\ nolist
\ nonumber
\ noswapfile
\ norelativenumber
" Now we can just write to the buffer, whatever you want.
call append('$', "")
for line in split(system('fortune -a'), '\n')
call append('$', ' ' . l:line)
endfor
" No modifications to this buffer
setlocal nomodifiable nomodified
" When we go to insert mode start a new buffer, and start insert
nnoremap <buffer><silent> e :enew<CR>
nnoremap <buffer><silent> i :enew <bar> startinsert<CR>
nnoremap <buffer><silent> o :enew <bar> startinsert<CR>
endfun
" Run after "doing all the startup stuff"
autocmd VimEnter * call Start()
insane_in_the_membrane
,以及它与实际代码的关系如何。因为那个人很聪明,这是我今天看到的最好的函数名称!:P