How to Show an ASCII Art Welcome Screen at the Top of the Vim Terminal

Get an inspirational quote from Homer, Yoda, or Spongebob

How to Show an ASCII Art Welcome Screen at the Top of the Vim Terminal
Some inspirational quotes from ascii art characters. Image by Author.

If you use vim, you’re probably just like me. You spend way too much time customising your config files to optimize your keyboard shortcuts and make things look pretty. If you’re new to vim or have yet to customise your config files, I apologise. By the time you’ve read this post, you’ll have a new addiction.

Today we are going to make a nice startup page for your vim (or neovim) setup. Each time you open vim, you’ll get a new random inspirational quote spoken by a random ascii art character.

If you’re unfamiliar with vim, it’s a simple command-line text editor pre-installed on pretty much every Linux or mac machine, runnable with the command: vim. If you’re on windows, you’ll be able to use it with Windows Subsystem for Linux in the exact same way as I do in this post. You may also follow along after setting vim up with a non-Windows Subsystem for Linux Windows guide here. Much of the vim community (including me) has shifted to neovim, a fork with a bunch of new features, so I’ll be providing instructions for both here.

You can install neovim with brew install neovim on mac or sudo apt install neovim on ubuntu.

Installing a plugin

To achieve what we want, we need to customize a plugin called vim-startify — the fancy start screen for vim. But first, we need to install it!

A screenshot of the vim-startify github page
Screenshot of the vim-startify readme.

Installation is made using a plugin manager like vim-plug (click the link for installation instructions) and is specified in your vim config file. With vim this file is found at ~/.vimrc. With neovim, this file is found at ~/.config/nvim/init.vim .

If you’re using vim-plug like me, add Plug 'mhinz/vim-startify' to your vim config file like so:call plug#begin(stdpath('data') . '/plugged')Plug 'mhinz/vim-startify'
" the rest of your plugins...call plug#end()" the rest of your vim config file...

Then close and reopen vim and install with the :PlugInstall command.

If you’re using another plugin manager, see that managers instructions for use. You’ll just need to add 'mhinz/vim-startify' somewhere else in your config file and run a similar command.

Default vim-startify configuration

By default, vim-startify looks pretty nice. Now, when you open vim, you should see the following:

Default vim-startify configuration. Image by Author.

However, the whole point of this article is to add different ascii art characters and quotes. Let’s do that now.

Customizing the vim-startify configuration

To customize our ASCII art character and quotes, we can add the below code to our vim config file (found at ~/.vimrc with vim and ~/.config/nvim/init.vim on neovim). If you want to be a bit neater, you can also put this into a file that loads after the plugins are loaded at:

  • ~/.vim/after/plugin/vim-startify.vim on vim.
  • ~/.config/nvim/after/plugin/vim-startify.rc.vim on neovim.

Essentially what we’ve done here is created a list of quotes and a list containing a collection of ASCII art I found online (mostly from www.asciiart.eu). Where there was attribution via the artist’s name, I have left that in the art.

There is a function here that randomly selects the art piece to display each time you open vim. Feel free to add ASCII art you personally like in the same format, but ensure you swap out ' characters for "or ` , as the ' character is used to specify the end of a string in vimscript.

I also like to add these vim-startify settings to view recent files at startup and set bookmarks (to my config files so I can customize even more), openable with shortcuts v and c .let g:startify_list = [
\ { 'header': ['    Bookmarks'], 'type': 'bookmarks' },
\ { 'header': ['    MRU'], 'type': 'files' },
\ { 'header': ['    MRU ', getcwd()], 'type': 'dir' },
 \ ]
 
let g:startify_bookmarks = [
\ { 'v': '~/.vimrc' },
\ { 'c': '~/.config/' },
\ ]if has("nvim")
let g:startify_bookmarks = [
 \ { 'v': '~/.config/nvim/init.vim' },
 \ { 'c': '~/.config/' },
 \ ]
endif

After you’ve customised your vim-startify configuration. Image by Author.

That’s all. Thanks for reading.