I’ve been playing around with plain text files lately for a few different reasons.

So I thought it would be worth learning a dedicated text editor.

Why Vim?

I’ve previously come across vi when managing text files on a server, so thought Vim (VI iMproved) is a good editor to learn. In particular MacVim, installed via homebrew.

What is Vim?

From what I hear vim is:

  • Simple
  • Powerful (once you understand it)
  • Flexible
  • Widely available

What steps I’m taking to customise Vim?

Vim starts off quite simple so thought I’d setup some basic customisations. With a focus on simplicity and purity. That is, to tweak as little as possible and use built-in/default features instead of 3rd party add-ins.

Package managers

One of the first things I wanted to tweak was the theme. My current preference being the Rosé Pine theme. Vim manages themes as packages / plugins.

A quick search listed a few different options for package managers:

  • Vim-plug
  • Vundle
  • Pathogen

With none of these being clearly the ‘best’ or most universal, with pros and cons for all of theme.

After a bit more searching I discovered, that from version 8, Vim has a built-in manager. However it requires a slightly less user friendly setup, but is otherwise simpler than the other ‘package’ managers.

Potentially I’ll opt for one of the more feature rich managers down the line, but the built-in manager seems to be enough for now.

plugins

Vim looks for packages in the following directories:

  • ~/.vim/pack/*/start for packages to always load.
  • ~/.vim/pack/*/opt for packages to optionally load.

With ‘*’ being anything. In my case I’ve used ‘plugins’ as the directory name. ~/.vim/pack/plugins/start.

When Vim starts up, after processing your .vimrc, it scans all directories in ‘packpath’ for plugins under the “pack/*/start” directory. First all those directories are added to ‘runtimepath’. Then all the plugins are loaded.

- from the vim :help package documentation

So what do we actually need to do, to install a package?

Ensure we have the required directory:

mkdir -p $HOME/.vim/pack/plugins/start

Copy the required files. (In this case the rose pine theme).

git clone --depth=1 https://github.com/rose-pine/vim $HOME/.vim/pack/plugins/start/rosepine/

We should now have the theme successfully installed. However it won’t be enabled.

General Config

So now that the theme is installed, how do we enable it?

Vim uses a special file .vimrc to store / manage configurations. So to enable the theme we need to update this file.

.vimrc Open the .vimrc with mvim $HOME/.vimrc

To enable the theme, we add some lines / comments to the .vimrc

" enable rosepine theme
set background=dark
colorscheme rosepine_moon

Whilst we’re editing the .vimrc we can also add some other configurations.

" Line number options:
" add absolute line number to current line
set number         
" add relative line numbers
set relativenumber

" Column highlighting options:
" Highlight column 80 as a soft-warning on line length.
set colorcolumn=80

Considerations

mvim vs vim

I initially tried this approach with vim directly in the macOS terminal. However it didn’t display the theme as expected. It turns out that the macOS terminal by default doesn’t support ‘true colours’. Which means that the theme won’t display as intended, but will instead display something similar, but different.

To get around this issue (without replacing the macOS terminal), I chose to install and use MacVim instead.

brew install macvim

neovim vs vim

NeoVim is a version of vim with some built-in ‘modern’ features. Such as a built-in LSP server, and lua scripting. However at this stage I’m not aware of the benefits of these features enough to use NeoVim. However I suspect I’ll end up using NeoVim down the line.