Invest in a good text editor

Scientists should invest time in a good text editor: pay the upfront cost of learning to use and customising a single editor for all of your text needs. This may be obvious to programmers, but less so to scientists who may have yet to recognise the benefits of a good editor.

Much scientific analysis and documentation can be achieved with plain text files (e.g., .py, .m, .f, .r, .tex, or .md). The default method to work with multiple file types is to use multiple IDEs (Integrated Development Environments): Matlab for m-files, Spyder or IPython notebooks for python scripts, TexStudio or TeXnicCenter for latex files, RStudio for R, or one of the countless editors for Markdown currently available.

Using a single editor has many benefits over using a range of editors within each IDE:

  • You need to know only one set of keyboard shortcuts
  • You can manage different projects easily since multiple file types aren’t scattered over multiple editors
  • Helpful features like Split Windows, Code Folding or Vim Emulation (a must have for me) will always be available
  • Your preferences such as dictionary language, colour scheme, code font, and indentation behaviour are consistent across file types
  • Good editors come with features you never knew you wanted like Multiple Cursors or Fuzzy Filename Matching to quickly switch files

Personal example: I use Sublime Text and to run a Python script I press Shift + Enter; to evaluate a single line in that Python script, I select it and press Shift + Enter; to generate a PDF from a LaTeX file, I press Shift + Enter; to convert a Markdown file to rich text, I press Shift + Enter. Jumping between these files requires a single keyboard shortcut.

Choose you editor

There are many editors to possibly use and a search for recommendations leads to countless subjective opinions. I recommend either Sublime Text or Atom. (Others will recommend Vim or Emacs for good reason, but these are more difficult to set up.) Both Sublime and Atom have minimal learning curve to get started. This leaves time to customise the set up.

Install the right plugins

Sublime and Atom (and most other editors) support many languages out of the box. Plugins then add extra features to really make life easy. These features may help automate completions, show documentation, run tests etc.

Examples of plugins for Sublime are Anaconda (for Python), LaTeXTools, and R-Box (for R). A quick search usually leads to the obvious choice for the language of interest.

Run a script (with the IDE’s assistance)

The plugins above come with shortcuts to run a script or file. A typical workflow of a scientist, however, is to run a script and then interact with the variables at the command prompt in a REPL-like fashion. Deciding how to proceed is the most difficult step. Despite what I said above, I recommend getting some help from your IDE at this stage.

Python and Sublime Text example: I run Python scripts from Sublime via Spyder’s runfile function in Spyder’s IPython console. Once the code has run I can inspect the variables in the console. Or, rather than running the file as a whole, I can evaluate a selected line or group of lines from Sublime. As noted above, I’ve set this up so it is all achieved by a single shortcut (see detailed instructions for Windows or Linux).

Matlab and Sublime Text example: I run Matlab m-files from Sublime in Matlab’s command window using the run function. Similarly, I can evaluate a group of lines by pasting their content from Sublime in the command window. As for the Python example, this is set up to work with a single shortcut (see detailed instructions for Windows or Linux).


By combining IDEs with Sublime Text, I maintain the benefits of having an IDE, but I also get to use my preferred editor instead of the editors that come with, say, Spyder or Matlab, which lack many features I want. Although it took me a while to figure out how to achieve what I’ve described above, it was time well spent. I recommend it if much of your time is spent editing scientific code, documentation, or publications.


Author: hugke729

PhD student in physical oceanography

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s