Programmers' editors

Programmers' editors #

For this class, consider using a programmers' text editor, a text editor with added features tuned to make programming easier. Syntax highlighting, linting, autocompletion, git integration, and even real-time collaboration are just a few of the features that these text editors have to offer. While there is a learning curve – as with everything – these options can make your coding process quicker and more pleasant. We describe how to install, configure, and use three text editors popular with CS51 students: VSCode, Sublime Text, and Atom. (Many thanks to Karina Halevy for instructions for VSCode and Rebecca Cremona for instructions and advice on configuring Sublime Text. Some of the advice on setting up Atom is adapted from material for Swarthmore’s CS75.)

Visual Studio Code #

We highly recommend using Visual Studio Code for CS51. It has live collaborative editing capabilities and good support for OCaml as well. See below for instructions on how to install and use it.

  1. Download and unzip Visual Studio Code from

  2. Unzip the downloaded file (if your computer hasn’t done so automatically) and drag the unzipped app into your Applications folder.

  3. On the leftmost sidebar, click the fifth icon from the top (it should look like a grid of four squares with the top right square floating away). This should open up a menu called “Extensions” on the second-from-left sidebar. On this sidebar, search for and install “Live Share”. Follow the instructions on the Live Share extension’s Details page to install it correctly. In short, you should see the words “Live Share” in the bottom left corner of your VS Code application window (right below the gear icon) when the installation has been completed.

  4. For OCaml support, search for and install “OCaml and Reason IDE” as well.

  5. To open up a lab, problem set, or project hosted on GitHub (as you’ll need to do throughout this course), click on “Source Control” on the leftmost sidebar - it’s the third button from the top of that sidebar, and it’s shaped like a couple of branches.

  6. To open up a repository, either select “Open Folder” and open up the local copy of the lab/problem set/project repo you’ve already cloned from GitHub or “Clone Repository” and paste in the URL of your copy of the repository (not the CS51 template copy, but your Github classroom copy, which should have your GitHub username somewhere in its name).

  7. You should now be able to open up any relevant files from the second-to-left sidebar.

  8. To run files and code, click View -> Terminal from the top menu (top of your computer, not part of application window) to pull up an integrated terminal. It should initialize the working directory to the top level of your repository.

For more information on Visual Studio Code’s support for live collaborating, see A guide to pair programming.

Sublime Text 3 #

You can install Sublime Text (which has a free evaluation version) from its website at

After downloading Sublime, begin by installing the package manager. This will allow you to install any other package you need. You can follow the instructions here.

After the package manager installs, restart Sublime. Now, you can install any package you want! To do so, go to ‘‘Tools’’ in the main menu and select ‘‘Command Palette’’, and then select ‘‘Package Manager: Install Package’’. From there, you can search or enter the package you want to install, and Sublime will automatically do it for you.

Some packages CS51 TFs recommend:

  1. SideBarEnhancements — This package provides enhancements to sidebar operations, by allowing you to do more by right-clicking files on the sidebar (for example, delete, cut, copy, etc.)

  2. GitGutter — This package will add subtle icons to the left side of your files so every time you hit ‘‘save,’’ you can see what change you’ve made since your last ‘‘git commit’’. This makes it really easy to spot certain mistakes, and also helps remind you to commit, since you can see your changes building up.

  3. Merlin — This adds OCaml-related fanciness. In particular: when you save your file, it looks for OCaml syntax errors and type problems. If you have a mistake, it puts a black dot next to the line with the problem, and makes detailed information on the error available via an error list.

    • First, install ‘‘merlin’’ by running in your terminal

      % opam install merlin

    • Now, use Package Manager: Install Package to install ‘‘Merlin’’

    • Lastly, to make sure that it works regardless of how you launch Sublime, run in your terminal

      % which ocamlmerlin

      and copy the path that you get. Then, in the preferences menu -> Package Settings -> Merlin -> Settings - User, paste in the following, replacing ‘‘my_path’’ with the path that you copied:

        "ocamlmerlin_path": "my_path"
  4. SublimeREPL — This will allow you to execute OCaml code directly from Sublime without having to copy/paste into an OCaml toplevel.

  5. Better OCaml — An improved version of the default OCaml package, giving better highlighting for certain OCaml code. Follow the instructions on the README to set it up.

Of course, this is a small set of all the packages that are available on Sublime. You do not need to install all or any of the packages above, and should feel free to explore and experiment with whatever you think would be helpful for your coding benefit.

The next important thing to do is to tweak your settings. On the main menu, go to Preferences and select Settings. Now, add the following to the ‘‘User’’ file (not the one that says ‘‘Default’'):

  "ensure_newline_at_eof_on_save": true,
  "tab_size": 2,
  "translate_tabs_to_spaces": true,
  "trim_trailing_white_space_on_save": true

With these settings, Sublime Text will draw a line at the 80 character column in your editor to help you with line lengths. The settings also provide good defaults for managing whitespace in your code. Feel free to play around with the settings and see what you like.

Atom #

You can install Atom from its website at

Because Atom was developed by GitHub, it integrates incredibly well with GitHub. In the bottom right, you can see which branch you are on, what files you have staged. You can easily push, pull, or fetch from within the editor.

Compared to Sublime Text, Atom is generally easier to customize, has more different packages and themes, and receives more frequent updates. The main downside of using Atom over Sublime is that Atom runs slower and uses more memory than Sublime.

Five useful packages for CS51 are:

  1. language-ocaml — Provides syntax support for for OCaml.

  2. linter — Detects and flags errors before compilation.

  3. ocaml-indent — Automatically indents your OCaml code. Remember, though, that this is not a replacement for the CS51 style guide.

  4. ocaml-merlin — Adds linting, autocompletion, type-checking, refactoring, and code navigation for OCaml.

  5. platformio-ide-terminal — Allows you to create terminal windows in Atom itself.

First, install ocp-indent (required for ocaml-indent) using OCaml’s package manager opam, as follows:

% opam install ocp-indent

Next, install all of the above packages from the command line using Atom’s package manager, as follows:

% apm install language-ocaml linter ocaml-indent ocaml-merlin platformio-ide-terminal

You can also install these packages individually in Atom by navigating to ‘‘Packages -> Settings View -> Install Packages/Themes’’, and searching for the packages listed above.

Others #

You might not like any of the options we presented, you might have a favorite editor already, or maybe Sublime and Atom aren’t your style. Some other text editors that have special support for OCaml programming (through merlin) include:

  • Vim
  • Emacs (Professor Shieber’s favorite!)