Sublime Text - learnclang/1-helloworld GitHub Wiki

This page contains guidance on one way of using Sublime Text for development with C.

untitled

Overview

Typically, source code is compiled via the terminal, and then executed, but Sublime Text provides the means to perform a "build" directly from within the program. In this guide, we'll setup Sublime Text in such a way that when you run the build-command, the currently edited file will get compiled and then immediately run, so we can witness the results without ever exiting Sublime Text.

Setting up a build system

Below you'll find a generic build-system for Sublime Text.

To create a new build-system

  1. Go to Tools
  2. Build System
  3. Create New Build System
  4. Copy and customise the following template to fit your compiler:
{
  "cmd": ["bash", "-c", "COMPILER_HERE '${file}' -Wall -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"],
  "selector": "source.c",
  "shell": false,
  "working_dir": "$file_path"
}

Where COMPILER_HERE refers to your chosen compiler, such as gcc, clang or cl.

Linting

Linting means to interactively highlight errors in your code as you go. To get it up and running with Sublime, you'll need a copy of Clang installed which is relatively straightforward to install on Linux, but a little more of a chore if you're on Windows so I'll give you the Windows version first.

To install linting for C in Sublime Text 3 on Windows.

  1. Install MinGW
  2. Install Clang
  3. Install SublimeLinter
  4. Install SublimeLinter-contrib-clang

To install linting for C in Sublime Text 3 on Ubuntu

  1. Install Clang
  2. Install SublimeLinter
  3. Install SublimeLinter-contrib-clang