Switching from Vim to Atom

(A Haskeller's Perspective) Posted on March 7, 2015 (last updated Aug 23, 2016)

I have been a Vim user for many many years, but have long wanted to switch to an editor that was more easily hackable. I tried Emacs and Sublime, but both had various hurdles that were just too annoying for me and both times I switched back to vim very quickly. However, I started using Atom a while back, and I have to say, I liked it from the start. I very quickly felt almost as productive as I was in vim, and in some ways I already much prefer Atom. (And since it’s JavaScript, we can write plugins in Haskell!)

Below are some tips that helped me transition from Vim to Atom.

Multiple Cursors

Multiple cursors, inspired by Sublime I think, are absolutely awesome. Many things that I would previously use a regexp for I now do much more quickly with multiple cursors. For example, here’s an example making a curried function uncurried:

Note that multiple cursors don’t have to stay in the same column, even if they start out that way. Each cursor responds to key commands independently. This is tremendously useful; for example, consider this example of removing parentheses:

Nor do they have to be on consecutive lines as in this example of removing some linebreaks:

On Mac, Shift-Control-Down (or Up) extends the cursor to the line below (or above). (You will want to disable the Mission Control and Application Windows shortcuts.)

Indentation

(No) Auto-indentation

I hate editors that try to be smart about indentation with a passion. I’ll decide my own indentation, thank you very much. The only thing I want an editor to do by default is to copy the indentation from the previous line (vim’s :set ai ). Thankfully, Atom does this out of the box.

(No) Tabs

One thing that is a bit annoying with Atom’s default settings is the treatment of tabs. By default, it’s using soft tabs, and that’s good, but it tries to be smart about recognizing multiple spaces as soft tabs and that’s not so good. The problem is that in Haskell code (in mine at least?) the indentation is not always an even number of “tabs”; instead, the indentation is dictated by the code. Here’s an example of where this can go wrong; all I do in this screencap is press space and then backspace:

This gets even more annoying when using multiple cursors, because now the behaviour on each line depends on whether Atom happens to recognize a soft tab or not:

Thankfully, this problem is easily solved by setting the length of a soft tab to 1.

Indentation help

Some help with indentation is useful though (when requested!). Multiple cursors can help here too. For example, we can use ⌘-D to add the next occurrence of the word or symbol under the cursor, and then use the atom-alignment package to justify each of those cursors:

Alternatively, if we want to align different words, we can create multiple cursors by ⌘-clicking on the keywords we want to align:

Haskell Support

Writing Haskell code is what I do for a living, and there are few things that I find absolutely essential; thankfully, all of these are well supported in Atom:

Syntax highlighting for Haskell is provided by the language-haskell package.

Atom supports CTAGS files out of the box, and it works great with the tags files created by hasktags; just call hasktags -x -c . in your project directory, and then you can jump to any tag using ⌘-Shift-R, or jump to the definition of the symbol under the cursor using ⌘-Alt-Down. (Incidentally, I know a lot of professional developers who do not use tags files. Use them! Once you start using them you will be so much faster navigating through source code that you will wonder how you ever did without.) Sadly, symbols-tree-view does not seem to work in Haskell projects, but that’s not a major problem.

in your project directory, and then you can jump to any tag using ⌘-Shift-R, or jump to the definition of the symbol under the cursor using ⌘-Alt-Down. (Incidentally, I know a lot of professional developers who do not use tags files. Use them! Once you start using them you will be so much faster navigating through source code that you will wonder how you ever did without.) Sadly, symbols-tree-view does not seem to work in Haskell projects, but that’s not a major problem. Support for cabal is available through my own ide-haskell-cabal backend for the excellent ide-haskell Atom package.

Incidentally, the same ide-haskell package also supports ghc-mod, but I don’t personally use it so YMMV. Note that if you do want to use ghc-mod you’ll probably want to use a recent version of ghc-mod (5.4 or up); it should work with either cabal or stack.

Miscellaneous

Finally, a few miscellaneous Atom tips and some non-default packages.

autoflow, installed by default, makes it possible to “reflow” a paragraph, much like gqap and co in Vim.

and co in Vim. ⌘-Shift-F is a project-wide search (with support for regular expressions, of course). For me this has pretty much replaced the use of grep , since the results are of course clickable.

, since the results are of course clickable. I find Atom’s autocompletion of brackets very annoying; I don’t want it to insert a closing bracket when I write an opening one; disable “Autocomplete Brackets” in the (standard) bracket-matcher package.

I like using Adobe’s Source Code Pro font; see Atom Initial Impressions by Quinn Rohlf for some info on how to use it in Atom. You might also want to take a look at Hasklig, a fork of Source Code Pro that adds ligatures for many of Haskell’s operators.

I make use of the following additional packages: