- Richard Feynman -
ITIC:Using a text editor
- 1 Reading instructions
- 2 Overview
- 3 Editor Basics
- 4 Editor continued
- 5 Links
We expect that you have read the page ITIC Editor.
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
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.
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.
In the videos (see below) we show this in practice.
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
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
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.
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.
Note: the program shown above causes a memory leak. Read about dynamic memory if you want to know more.
Video lecture and slides
Extra videos (bonus)
Here are some extra, "live", videos for the ambitious student (included from another module on this wiki):
- ITIC - Using an editor - Emacs (All, live) | Emacs - Basics - 1 - buffers | 2 - Start pause exit | 3 - Searching | 4 - mark cut paste | 5 - Moving in the buffer | 6 - File management | 7 - Window management
Summary lecture slides
- If any?
- A page on this wiki about Editors
- A page on this wiki about Emacs
- Search this wiki for pages containing the word "editor"
- The Beginner’s Guide to Nano, the Linux Command-Line Text Editor
- Linux Nano Editor Explained for Beginners (10 Examples)
- Nano/Basics Guide
- How to Use Nano Text Editor Commands in Linux
- A Beginner’s Guide on How to Use Nano Text Editor in Linux
- Introduction to the nano Text Editor
- Atom Flight Manual
- Getting Started with Atom
- Overview of Atom IDE
- A Quick Look At The New Atom IDE
- Atom editor tutorial
- Practical Emacs Tutorial
- A Guided Tour of Emacs
- Absolute Beginner's Guide to Emacs
- Getting Started With Emacs
- Emacs Beginner's HOWTO
- GNU Emacs reference card (PDF) keyboard shortcuts
- gedit Text Editor (gnome.org)
- gedit text editor (geek-university)
- Turn Gedit Into an Advanced Editor (fosspost)
- How to Edit Text Files Using the gEdit Linux Text Editor (lifewire)
- gedit (ubuntu.com)
Where to go next
The next page is ITIC:Using_a_text_editor_-_Exercises.