Issue 019 – October 31, 2020

You need a better text editor

Hey there,

It’s Robin from CFD Engine – another week, another CFD note – but no spookiness, I only just realised it’s Halloween 🎃

It’s been school holidays here, aka “lockdown lite”, so the closest I got to actual work, was setting up a new laptop. My top 3 takeaways:

  1. I actually don’t use most of the software on my old laptop
  2. Thank heavens for password managers
  3. I have a text editor “problem”

It’s not a problem…honest

One of the first things I did on my new machine was to install three text editors – one for my notes, one for writing stuff like this & one for editing code/OpenFOAM cases.

That’s on top of the notes app, the native text editor & the word processor that come pre-installed.

They’re pretty niche additions, but still, does anyone need three text editors?

Death & Taxes

As an OpenFOAM user, some things are certain:

  1. You’ll spend a lot of time on the command line
  2. You’ll spend a lot of time editing text files
  3. You’ll spend a lot of time Googling error messages 😉

The first gets easier with time. The last one drops off as you start recognising them. But the middle one is a constant.

Do yourself a favour, say goodbye to Windows notepad & grab yourself something more coding-friendly.

A better option

Text editors aimed at developers are built for working with directories full of little text files. They’re just as useful for editing a single OpenFOAM case as they are for a huge codebase. So, even if you have no intention of ever touching the OpenFOAM source-code, a decent code editor is definitely worth grabbing.

There are hundreds of code editors, but I recommend you grab Atom – an open-source editor, built by GitHub. It works on all major operating systems, has loads of packages to give it super-powers & best of all it’s free.

A word on vi (& emacs)

You might have watched over the shoulder as a wise-old sysadmin ssh’d into a machine, opened a text file in the terminal 🤯 and proceeded to edit it with a series of incomprehensible key presses.

That was probably vi or emacs – two of the most powerful text editors that you’ll never get the hang of. If you think OpenFOAM has a steep learning curve, take emacs for a spin.

It is worth spending some time to grasp the basics of vi (or emacs) though. They make quick remote edits a breeze & can save you a ton of time on cloud instances.

A couple of things to try

If you are checking out Atom, then here are a handful of things to try that might make #openFOAMlife a little more comfortable & help you avoid a few pesky typos.

fuzzy finder – Quickly open files, even if you aren’t quite sure of their name, or which folder they live in. Press ctrl-t, type any part of the file name & it’ll bring up suggestions.

multiple cursors – You can edit multiple lines at once. ctrl-click wherever you’d like to add another cursor & edit away, great for editing multiple boundary conditions in one go.

select nextctrl-d will select the word nearest your cursor (or any string of characters &/or numbers). Press it again to select the next occurrence in the file (keep going to select them all) & then you can edit them all at once.

comment toggling – comment out the lines in your dictionaries that you’d like OpenFOAM to ignore. Select the lines you want to comment out & press ctrl-/ to add // to the start of each line. Do it again to uncomment them. Good for testing changes, as opposed to just deleting stuff.

keyword suggestion – Start typing and Atom will suggest keywords that it’s found in the files you have open. Good for avoiding typos in variable names across files.

BTW – you can do all of the above in vi & emacs but I thought you might like to save that challenge for another day 😉

You do you

All developers have a favourite code editor, if you’ve been using OpenFOAM for a while, then you probably have one too. If you’ve got a fave, then I’m not looking to convert you.

But, if you think you might be missing out, do yourself a huge favour & grab Atom. If Atom doesn’t cut it, then drop me a note, I’ve got a couple of other suggestions that you could try out.

What’s your text editing weapon of choice? Is there a particular plugin or feature that you can’t do without? What should I be checking out? There’s always space for another text editor.

Until next week, CFD safely,

Signed Robin K