Atom

Introduction

Atom is an open source text editor developed by GitHub. It's a modern text editor like Sublime Text, but unlike Sublime, it's free to use.

Install

Visit Atom's website and follow the instructions to install it on your computer.

Example: greet.py

Alright, by now, you should have Atom 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 a project

Now let's open up Atom!

For Mac users, you'll most likely find Atom in your Applications.

For Ubuntu users, you'll most likely find Atom by putting it in the search bar.

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

Click on "File > Add Project Folder..." in the menu bar. Highlight the example folder you just made and open it. It should appear in the sidebar as an empty folder.

empty atom

Editing files

Now we have Atom 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, Atom should look something like this:

atom greet

To save, you can just type ctrl + s. If you haven't already, save this file as greet.py in the example folder. Notice that it appears in the sidebar under example! This will be helpful for navigating projects that are more than one file.

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

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!

Keyboard Shortcuts

For Mac users, replace all the ctrl sequences with cmd

  • ctrl+s : saves the current file
  • ctrl+z : undo
  • ctrl+y : redo
  • ctrl+[ : indent a line or a group of lines
  • ctrl+] : dedent a line or a group of lines
  • ctrl+tab : moves you to the next tab
  • ctrl+shift+tab : moves you to the previous tab
  • ctrl+f : search for a word
  • ctrl+shift+f : searches through all tabs
  • ctrl+shift+p : This one's important. This opens up a little panel of tools! You can do things like type "ss python" which will set the syntax of your file to python or "reindent" will help you reindent a file you paste in (this will be helpful in future labs!)

This guide only scratches the surface of all of Atom's functionality. If you are interested in diving deeper into Atom, check out it's documentation! Remember, if there's something you wish Atom could do, it probably can! Just Google it!