Never confuse education with intelligence, you can have a PhD and still be an idiot.
- Richard Feynman -

ITIC:Using a text editor

From Juneday education
Jump to: navigation, search

Reading instructions

We expect that you have read the page ITIC Editor.


Basic functionality

When developing software you write source code (plain text). An editor is a software dedicated to that task alone. With an editor you can:

  • open a file, and read the content to a buffer
  • save a file, by reading from a buffer
  • edit (update) the content in a buffer


Common features among editors are:

  • syntax highlighting - an editor normally presents source using bold or italic fonts and sometimes different colors. This is just presentation of the source code - the source code itself does not contain any information about bold or italic fonts etc
  • indentation - an good editor helps you to indent your program. Indenting is done differently for various programming languages. The indentation is just for making reading code easier - the compilers etc care nothing about indentation
  • brace matching - an editor can display where a block of code begins and ends

Some editors also provide:

  • word completion - the editor can complete a word for you (if you've written 'toUpp' the editor has means to figure out that you probably mean to write 'toUpperCase' and provides a way for you to go for this guess and thus you can skip writing some letter
  • syntax check - the code you write is constantly checked against the programming language's syntax and will present syntax violations directly and thus give the user instant feedback
  • VCS integration - the editor can manage various VCS (Versioning Control System) tasks

Editor Basics

Open a file

Most of the times you want to edit a file that already exists. You can open file in different ways, e g:

  • use the menu from the editor - requires that the editor is already started
  • start the editor from a terminal with the file supplied as arguments (on the command line)

We strongly suggest the latter. No let's change that, we require that you do the latter. So, assuming you want to open the file readme.txt with the editor Gedit you type the following in a terminal (running bash):

gedit readme.txt &

The ampersand & is necessary to start the gedit window in the background, so that you can keep using the terminal. Otherwise bash will wait for the gedit process to finish before you can use the terminal again.


When you open a file in an editor the content of that file is read into a buffer (in the editor's memory) and this buffer is presented in some kind of text area (could be a separate GUI or inside a terminal). When editing (updating) the content in the text area you're updating the buffer and not the content of the file on the disk. It is not until you save that the file is stored to disk.

In the two pictures below we can see that we've edited the buffer - and not yet saved the content of the buffer to file. In the terminal windows we can see that there no files created. Note that there is an asterisk (*) in front of the file name. This indicates that the file has edits not saved.

Editor-term-unsaved2.png Editor-buf-unsaved2.png

In the two pictures below we can see that we've saved the content of the buffer to file. In the terminal windows we can see that the file exists and that the content of the file is the same as the content of the buffer in the editor. Note that there is no asterisk in front of the file name. This indicates that the file's edits has been saved to file.

Editor-term-saved.png Editor-buf-saved.png

In the videos (see below) we show this in practice.

Save file

As we discussed in the section above (Buffer) you need to save your changes to update (or rather replace) the content of the file with the content of the buffer in your editor's window.

Saving a file is typically done in any of the following ways:

  • use the editor's menus
  • use a keyboard shortcut (e g Ctrl-S)

We suggest you get used to using shortcuts since this makes it possible to work faster.

Close the editor

An editor does not use a lot of CPU when not in use so closing an editor just to start it again might slow you down. Close the editor when you're not going to use it for a while. The same as with the other actions you can close the editor via the menus and with a keyboard shortcut (e g Ctrl-q).

Create a new file

This is done the same way as open an existing file. The editor creates an empty buffer for you (no file yet!) and as soon as you save the file the content (of the buffer) is written to the file.

Editor continued

Syntax high-lighting

There are no formating information (font, font size, color ..) in a text file. Still some editors display text in different colors and with bold and italic fonts. This is done by the editor after the file has been read - the editor displays the content differently based in the type of information in the file. If we open up a file with some source code in the programming language C then gedit, and most likely other editors as well, displays the content with color and fonts based on the syntax of the C language.

In the left image below you can see the content of a C file printed to the screen using the cat command - no formatting is done at all, it's just plain text. In the right image you can see the same content displayed using syntax high-lighting for C.

Syntax-hilite-term.png Syntax-hilite-gedit.png

Note: the program shown above causes a memory leak. Read about dynamic memory if you want to know more.


Video lecture and slides

  • TODO

Extra videos (bonus)

Here are some extra, "live", videos for the ambitious student (included from another module on this wiki):

Summary lecture slides

  • If any?

Further reading

This wiki

External links - nano

External links - Atom

External links - Emacs

External links - Gedit

Where to go next

The next page is ITIC:Using_a_text_editor_-_Exercises.

« PreviousBook TOCNext »