When I start Vim without any files, I always see this:

              VIM - Vi IMproved

               version 7.4.580
           by Bram Moolenaar et al.
 Vim is open source and freely distributable

        Become a registered Vim user!
type  :help register<Enter>   for information

type  :q<Enter>               to exit
type  :help<Enter>  or  <F1>  for on-line help
type  :help version7<Enter>   for version info

How can I change this?

Specifically, I'd like to put the output of a shell command (fortune) here.

I know about vim-startify; but I don't need all those features. I just want to show some simple text...


Actually the answer is in startify. In startify.vim around line 15 we can see

 autocmd VimEnter * nested
\ if !argc() && (line2byte('$') == -1) && (v:progname =~? '^[-gmnq]\=vim\=x\=\%[\.exe]$')
\ | if get(g:, 'startify_session_autoload') && filereadable('Session.vim')
\ | source Session.vim
\ | else
\ | call startify#insane_in_the_membrane()
\ | endif
\ | endif
\ | autocmd! startify VimEnter

So the relevant thing is the VimEnter auto command which is called "after doing all the startup stuff".
The following if checks whether this is an empty session (by checking for arguments like filename). Basically you can put your code in the place of the second if, which is the startify-specific code.

  • 6
    ... I'd like to know who thought of the function name insane_in_the_membrane, and how that has remotely anything to do with its actual code. Because that person is brilliant and this is the best function name I've seen today! :P – Doorknob Feb 8 '15 at 23:43
  • 1
    @Doorknob Function was renamed from "start" to "insane in the membrane" by Marco Hinz. Given the original lyrics by Cypress Hill I'd guess he was worried about how big the method was getting. Or maybe was just listening to it at the time. – jalanb Feb 9 '15 at 9:59

Here's the code that I extracted from vim-startify; the key parts are creating a new buffer on the VimEnter autocmd, putting some text in that, and then mapping the i to start a new buffer and then go to insert mode.

I put the below in a little plugin which adds some settings and such, but the basic concept is exactly the same.

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

    " Start a new buffer ...

    " ... and set some options for it
        \ 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)

    " 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>

" Run after "doing all the startup stuff"
autocmd VimEnter * call Start()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.