Sublime

Table of Contents

Introduction

Sublime is a friendly text editor known for its slick user interface, numerous features, and snappy performance that provides a combination of many amazing features from modern text editors (and more)!

Sublime is easy to use, and extremely fun to master (I mean, who doesn't want to use multiple cursors in vim mode while — you get the picture, do things with CS words that don't quite make sense right now). This guide will get you started with Sublime, with a few basics and essential tools for your workflow in CS61A. If there's something you want Sublime to do, it's likely possible! A quick Google search will probably show you a plugin you can install to extend Sublime's functionality.

Getting Sublime on your own computer

You can go to Sublime's website to download it.

Example: greet.py

Alright, by now, you should have Sublime installed. You have the option of either finding the Application or opening it up from the terminal. Recall from Lab 0 that you can open a terminal on the school computers by pressing Ctrl-Alt-t.

Let's first create and navigate to a directory called example, using the UNIX commands you learned in Lab 0:

mkdir ~/example
cd ~/example

Opening files

Now let's open up Sublime!

For Ubuntu or Mac users, you'll most likely find Sublime in your Applications.

For Windows users, you'll most likely find Sublime in your Program Files.

Sublime will open up to a blank file. We can start writing our program!

blank sublime

Editing files

Now we have Sublime open, we can begin writing our first Python file. Don't worry, we don't expect you to know any Python yet! All you have to do is type in the following:

def greet(name):
    print('Hi', name, ', how are you doing?')
    print(' - Python')

Once you've finished typing, Sublime should look something like this:

Greet function

To save, you can just type Ctrl + s. If you haven't already, save this file as greet.py.

Running Python

In this class, you will be switching between your text editor and Python a lot — writing code and testing code.

Back in our terminal, we're currently in our example directory. Let's play around with our code. In the terminal, start by typing

python3 -i greet.py

This command does the following:

  1. python3 is the command that starts Python
  2. The -i flag tells Python to start in interactive mode, which allows you to type in Python commands from your terminal
  3. greet.py is the name of the Python file we want to load

Notice that the Python interpreter says >>>. This means Python is ready to take a command.

Recall that we defined a function called greet. Let's see what it does! Type in the following:

greet('Michelle')

Python will then print out

Hi Michelle, how are you doing?
 - Python

You probably want Python to greet you and not me. So if your name is John, you should also type:

greet('John')

and Python will print

Hi John, how are you doing?
 - Python

Our code works! Let's close Python by typing in

exit()

There are a couple of ways to exit Python. You can type in exit() or quit(). On MacOS and Linux, you can also type in Ctrl-d (this doesn't work on Windows).

Congratulations, you've edited your first file in Sublime!

Keyboard Shortcuts

Sublime has a some swell keyboard shortcuts. Here are a few useful ones! (for Mac users, replace all the Ctrl sequences with cmd)

Control Panel

This guide only scratches the surface of all of Sublime's functionality. Remember, if there's something you wish Sublime could do, it probably can! Just Google it!