A text editor is a software that writes and edits simple text. They are useful for uncomplicated writing and word processing. Some of their applications include programming and writing computer configuration files.
You can use two kinds of text editors on a Raspberry Pi: Desktop graphical editors and Command-line editors.
Desktop Graphical Editors
Desktop graphical editors are text editors that have a GUI (Graphical User Interface). You can access them through the Raspberry Pi Menu or the Terminal. Moreover, to use a desktop graphical editor properly, you need to have a mouse and keyboard.
Some of the desktop graphical editors that you can use on a Raspberry Pi are::
- Text Editor
- Thonny
- Geany
- Mu
- GVim
Command Line Editors
Command-line editors, on the other hand, can only be accessed using the Terminal. Unlike desktop graphical editors, command-line editors can be used with only a keyboard. They use keyboard shortcuts as an alternative to a point-and-click interface.
Some of the command-line editors you can use on a Raspberry Pi are:
- Nano
- Vim
- Vi
- Emacs
In this tutorial, we are only going to explore 1 of each kind: Mu for the desktop graphical editors and Nano for the command-line editors.
Mu
Mu is a text editor and IDE (Integrated Development Environment) specially made for Python programming. It is known for being easy-to-use as its target users are beginner users.
Installing Mu
Before you install Mu in your Raspberry Pi, make sure your Raspbian OS is up to date by entering sudo apt-get update
and sudo apt-get dis-upgrade
in the terminal. There are two ways you can get Mu in your system. One is by accessing Menu on the top left side of your desktop.
Under the Menu, go to Preferences, then choose Recommended Software.
A list will pop up that displays all recommended software for the Raspberry Pi. If you don’t see Mu, you can enter Mu on the search bar on the bottom right of the window.
Click install (I already have Mu so I didn’t get an install button on Figure 2).
After installation, you can start Mu by going to Menu > Programming > Mu.
Another way of installing Mu is by using CLI (Command Line Interface). While on your desktop, start the terminal by clicking the blackboard icon in the quick launch toolbar. Alternatively, you can open it by pressing CTRL + ALT + T.
In the terminal, enter sudo pip3 install mu-editor
to install mu.
You can start Mu by simply entering mu-editor
.
Mu modes
The current version of Mu offers 4 modes. You can change them depending on what you intend to use Mu for. For now, we are going to use it for Python programming.
Select the Python 3 mode and click OK.
Writing Code in Mu
Let us now write the canonical Hello World program. Copy the line below and save your file. No need to add .py on the file name as Mu already assumes the file type when you set the mode to Python 3.
Next, click Run to run the program. You will see the output on an integrated Python shell below the text editor.
To stop the program, click Stop.
Useful Mu features
One useful feature of Mu is error highlighting. Mu checks for errors and highlights them in red so you can detect coding mistakes without a problem.
Additionally, you can click Check to search for errors on your code without running the program.
GNU Nano
GNU Nano is the native text editor of most Linux distros. It’s easy to use and offers a myriad of keyboard shortcuts, which are useful when writing in a computer’s CLI (Command Line Interface).
Nano comes with Raspbian as a default editor so you don’t need to install it explicitly. You can just start nano by entering the nano
command.
Nano is a straightforward text editor. You just type text directly and you always see the keyboard shortcuts under. The carets on the shortcuts stand for the CTRL button. So for example, if you need help, just type CTRL + G. Same goes with the other shortcuts. If you want to cut a selected text, simply type CTRL + K. One thing to note about though. Cutting and pasting using Nano shortcuts won’t let you get the text out of Nano to another software and vice versa. In order to do that, you must press the Shift and Right Click button. This will bring out the usual copy-cut-paste options you see on standard word editors. Using these, you can already get the text in and out of Nano.
Furthermore, a new and unnamed file will display new buffer on the title bar. After writing text or introducing change to the file, the title bar will show Modified at the top right side.
I entered a sample text for demonstration and saved it using the shortcut CTRL+O,