Vim + Swift

Its been a few years since I last participated in Advent of Code, and I actually forgot about it until I saw some folks mention it on Mastodon. I’ve also been working on my Swift + iOS development skills this year, contributing to Pocket Casts iOS a few hours a week in addition to my regular web dev work at Automattic.

So I decided I’d take up Advent of Code again this year and use Swift to solve all the coding challenges to improve my skills a bit more. All of my Swift development so far has been in Xcode, but I also enjoy using Vim as much as possible. Since I discovered the wonderful world of Vim plugins a few years ago and realized I could do everything I enjoy in vscode right in a terminal window I’ve been using it as much as possible for smaller projects. It is something I like to do since the more comfortable and familiar I get with vim the less awkward it is to do more complicated work directly on the server when needed. Anyways, after solving the first 2 days of coding challenges, I decided that I needed some syntax highlighting in Vim because I was making silly mistakes that could have been avoided if every character on my screen wasn’t the same colour.

I went to my favourite vim plugin repository, VimAwesome, and searched for Swift. I was surprised to see, about 5 results down, that there was an official Apple vim plugin. Its buried a few levels deep in the Swift repo but it works, and its pretty awesome. It just wasn’t very straight forward to setup. Simply installing the repo as a plugin didn’t work, and after reading up on the documentation for vim-plug I discovered you can target a subdirectory in a repo.

Plug 'apple/swift', { 'rtp': 'utils/vim' }

… and just like that my monotone green editor window is now full of productivity-inducing syntax highlighting!

Before
After

And since I already had ALE installed all I needed to do was install SwiftLint and SwiftFormat and I’ve got linting and formatting ready to go as well.

Leave a Reply

%d bloggers like this: