21

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

200_success
  • 9,549
  • 5
  • 51
  • 64
Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271

3 Answers3

7

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.

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
johannes
  • 589
  • 3
  • 7
6

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
        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()
Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
1

Perhaps it's a bit of a hack, but the following one-liner anywhere in the .vimrc file will effectively truncate the Vim splash screen to a length of zero:

    set shortmess+=I
softronyx
  • 11
  • 2
  • 1
    "Perhaps it's a bit of a hack" - I don't think so. According to :help shortmess this suppresses the :intro message and that's what it does. – Friedrich May 24 '23 at 15:35