My Perfect VS Code Setup

The role of the traditional Systems Administrator is slowly but surely dying. Clicking on buttons in GUI’s is making way for configuration as code. As such, you text editor is more important than ever. I’ve had several discussions about various setups, so here is mine.

For conxtext on my choices, my day to day activities in a text editor are mainly:

  • Terraform
  • Python
  • Puppet
  • Go
  • Configuration file editing (yaml, json etc)

Preamble

There are a few things that need to be installed before VS Code is functional for me. Firstly, you obviously need VS Code. I also need the following:

Theme and font

Whilst this shouldn’t matter to you at all, nerds sure do like to talk about unimportant things like font and color theme. I use One Monokai and Hack.

Extensions

On to the important stuff. Extensions are what make VS Code so customizable. Most of these are formatters or extensions that offer autocompletes (or InteliSense as VS Code refers to it).

Probably the most important one is Settings Sync. This syncs your settings to a GitHub Gist, allowing you to have exactly the same configuration across all of your devices. If like me, you switch between macOS, Windows and Linux pretty regularly, this is absolutely invaluable.

Settings

Most of the default settings are sensible, but there are a few tweaks I would recommend making. First off, set black to be your default formatter and set the path to it (usually as below, but which black will give you what you need)

Now for some Go and Puppet settings. These are easier to copy and paste, so open the command palette (cmd-shift-p on macOS, ctrol-shift-p on Linux and Windows) and type in Open Settings (JSON), and add in the following.

  "go.lintOnSave": "file",
  "go.lintTool": "golangci-lint",
  "go.lintFlags": ["--fast"],
  "go.formatTool": "goimports",
  "go.alternateTools": {
    " goreturns": "gofumports"
  },
  "editor.formatOnSave": true,
  "[puppet]": {
    "editor.formatOnSave": false
  },

These settings will set up linting and formatting for Go - you will be prompted to install any missing Go dependencies. We then are turning on the most important setting - enabling formatting when you save a file. This means you never need to think about formatting when you save a file. I did however, find an issue with formatting on save with Puppet files, so that is disabled here.

Prettier+ will handle many file formats - go through the ones you use often (json and yaml here) and set Prettier+ to be the formatter for those languages. Do not set it to be the default formatter. It will overwrite all of your other formatters.

Conclusion

There are many other settings that make up the perfect coding environment, but this covers most of what I consider essential. My settings are on a public Gist if you are interested in seeing what else I have configured.