Two Steps for Highlighting and Indenting Swift Code in Vim

Yurakucho Compacted PanoramaWith a working swiftc on your headless Raspberry Pi 2, it probably won’t be too long before you find yourself writing some simple Swift code in Vim. On my Pis I use Keith Smiley’s swift.vim, installed without a plugin manager to keep things simple.

(For a more general overview of how to manually install VIM plugins, see Dayne Jones’ post on howchoo.com. Note that you will also probably have to turn on syntax highlighting and indentation in your .vimrc, as below.)

Step 1: Install swift.vim

mkdir -p ~/.vim/bundle && cd ~/.vim/bundle/
git clone https://github.com/keith/swift.vim

Step 2: Update ~/.vimrc

I have just 3 things in mine. In order, from top to bottom:

  1. Add swift.vim to runtimepath: set runtimepath+=~/.vim/bundle/swift.vim
  2. Turn on syntax highlighting: syntax on
  3. Enable file-type based indentation: if has("autocmd") filetype plugin indent on endif If you want to add some comments, don’t forget that comment lines in .vimrc start with ", not # or //.

And that’s it!