Text editors

Sometimes, you might need to edit a file on your Raspberry Pi: perhaps to edit the /etc/network/interfaces file in order to reconfigure your Raspberry Pi network interfaces, or you might need a text editor to write a document.

Fortunately, there are several text editors installed with Raspbian. The most commonly used text editors are:

  • nano
  • vim

nano

Originally created in 1999 by Chris Allegretta, nano is the easiest text editor to use included on the Raspberry Pi.

nano

The nano text editor

To edit a file in nano, you simply need to start typing. Once you have made changes, you need to save them and exit. The commands that you see at the bottom of the screen can be accessed by pressing the Ctrl key on your keyboard followed by the letter.

  1. For instance, to exit after you have made changes, press Ctrl + x.
  2. You will then be asked whether you want to save these changes. To do so, press y.
    nano

    Saving changes in nano

  3. You now need to enter the filename that you want in order to save the file. Once you have done this, simply press Enter and your file will be saved.
    nano

    Confirming the filename of the file you are saving

  4. To load the file you have just saved, just run the nano command as shown in the following screenshot:
    nano

    Selecting the filename that you want to save the file as

vim

The other text editor installed on your Raspberry Pi is the vi text editor. The vi editor was originally created for Unix-based operating systems by Bill Joy in 1976.

The name vi is derived from the shortened abbreviation of the word visual. The vi editor is one of the most widely used text editors in Linux.

vim

The vi text editor

The vim (improved vi) editor is a bit more complicated to use than nano. The vi editor is designed to stay out of your way, and as such, you won't see any menus or unnecessary information on the screen.

The vim editor has several different modes that you use to operate it. One of the modes is insert mode. When you are in insert mode, you can use vi like you would use the nano text editor, but here you simply type the text and use the arrow keys to navigate the file. To get into insert mode, press the Insert key or type a capital I.

vim

The vi text editor in insert mode

In order to save the file, we need to enter in the command mode. To do this, press the Esc key followed by the : key. This will bring up a command prompt at the bottom of the vim window.

vim

The vi text editor in command mode

There are many different commands available in vim, as follows:

Command

Description

w

This writes the file to disk

q

This is used to quit vim

dd

This deletes the current line of text

x

This deletes the character where the cursor is

These commands can be entered in Command Prompt, or when you are navigating the text and are not in insert mode.

An example of these commands is the wq command. This command saves and quits vim when you press Enter. You won't be asked whether you want to save your changes, as vim knows what you want, based on the command you give!

If you don't want to save your changes, simply enter the q! command.

There are many other text editors that can be installed onto your Raspberry Pi, such as geany.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset