Andrei Maxim

March 12, 2024

Exploring Visual Studio Code

I've decided to explore a potential migration from Emacs to Visual Studio Code, mainly because I've been planning for a while to get up to date with HTML, CSS and JavaScript and VS Code seems to have support for the most recent tools and practices on the front-end side.

Here's how the current setup looks like when opening my version of the 99 bottles of OOP project (with increased font size for visibility):

image.png


Settings

A lot of people prefer to have a lot of information displayed by the editor, including a minimap, Git blame information and so on, but I prefer to have a much more minimal UI (Cursive IDE is my main inspiration):

  • Files: Auto Save afterDelay
  • Editor: Font Size: 16
  • Editor: Font Family: Iosevka SS08
  • Editor > Guides: Indentation unchecked
  • Editor: Line Height 20
  • Editor > Minimap: Enabled unchecked
  • Workbench: Startup Editor none
  • Workbench > Activity Bar: Location hidden
  • Workbench: Color Theme Tokyo Night
  • Breadcrumbs: Enabled unchecked
  • Workbench > Editor: Show Tabs none
  • Rubocop: Mode Run only globally, never via Bundler

I have altered the default setting for Rubocop because I work almost exclusively with Ruby and Rails projects and most of them don't have Rubocop in their Gemfile. However, I did setup a global config file with the following contents, since I found that the rubocop-rails-omakase gem disables all the cops I don't want and enables the ones I'm OK with:

# Omakase Ruby styling for Rails
inherit_gem:
  rubocop-rails-omakase: rubocop.yml

Extensions

I don't use too many extensions, because I've found that, regardless of the editor, extensions tend to impact performance. Also, I've seen cases where extensions don't advertise well enough what default behavior they changed, which can cause confusion.


I don't use Shopify's Ruby extension as the code I write isn't using Sorbet and I don't use LSPs, except for the "Go to definition" feature, which is currently missing from ruby-lsp anyway.

I'd like to highlight edamagit, which is a port of the excellent Magit package for Emacs. I've become so used to working with Magit that I don't think I could switch to another editor with less features.

Keyboard Shortcuts

I won't cover the general movement keyboard shortcuts, but there are a couple of default shortcuts that I had some issues discovering, probably because each editor calls the editing space in a specific way (e.g. for Vim is buffer, for Emacs is window, for VS Code is editor)

  • Find file: Ctrl+p
  • Find action: Shift+Ctrl+p
  • Toggle sidebar: Ctrl+b
  • Magit status: Alt+x, g
  • Split horizontally: Ctrl+\
  • Split vertically: Ctrl+K, Ctrl+\
  • Close split: Ctrl+K, w
  • Move to split: Ctrl+K, Ctrl+<arrow>

I'm thinking of remapping the Magit Status shortcut from "Alt+x, g" to "Ctrl+K, g" for consistency, especially since I map Ctrl to Caps and it's easier to press than Alt, but I generally tend to avoid having a very customized set of keyboard shortcuts.

What Is Missing

The main feature I'd wish I'd have in VS Code is the ability to format the code. There's a built-in way to do this in most editors out there (vim, Emacs, Intellij products, etc), but it seems like VS Code is relying on external formatters and I couldn't find one that is flexible enough for Ruby, like there's Prettier for HTML, CSS, and JavaScript (there is a prettier-ruby plugin, but it doesn't allow any configuration options).

The Rubocop VS Code extension comes with a formatter, but it only formats code in order to fix an offense and it obviously doesn't work that well when most cops are disabled by default. There's also Rufo, but the options are quite limited.
 
Ideally there would be an extension like aggressive-indent-mode for Emacs.

About Andrei Maxim

Professional Ruby guy.