4.3. Editing text files using nano#

GNU nano is a command-line text editor with features like undo/redo, syntax colouring, interactive search and replace and more.

To open the program, type nano in a terminal session.

4.3.1. Create new file#

To create a new file, use nano followed by the name of the file you would like to create.

For example:

nano exercise.txt

This will open the file for writing (Fig. 79).

../../_images/nano-create-file.png

Fig. 79 Creating a file in nano#

You can start typing text at this stage.

4.3.2. Pasting text from clipboard#

To copy and paste text from a different program, for example, a web browser into a file you are editing in nano, do the following:

  1. Copy the text from the program to clipboard using Ctrl + c

  2. In nano, move the cursor to the position where you would like to paste the text

  3. Use the Shift + Ctrl + v keyboard shortcut to paste the text

4.3.3. Saving changes#

To save the file, use the shortcut Ctrl + o.

This corresponds to the ^O Write Out function displayed at the bottom (Fig. 80). The ^ here refers to the Ctrl key.

../../_images/nano-write-out.png

Fig. 80 To save changes use the Write Out function#

A prompt like the following will be displayed at the bottom (Fig. 81):

File Name to Write: exercise.txt
../../_images/nano-save-file.png

Fig. 81 Enter a file name to save the file#

Press the ENTER key to accept the default value — the original file name.

4.3.4. Exit nano#

To exit nano, use the Ctrl + x shortcut.

If there are no changes, nano will close. If there are unsaved changes, it will prompt you to save them (Fig. 82).

../../_images/nano-save-changes.png

Fig. 82 Confirmation to save changes to file#

Type y to save changes or n to discard them.

Comments