Etc : Nano - write out

Nano is a very capable text editor and can work with multiple files, so lets quickly create a new one from the Intro section of my_help.txt....

Do Alt+A and Mark the Intro Section, then Ctrl+O to get to the Write Out menu. In the Write Selection to File: type in intro.txt and hit Enter.

Nano: selecting text to create a new file.

Now to see that file hit Ctrl+R for Read File and when in Read Mode do a Alt+F for a New Buffer and in the File to read into new buffer [from ./]: type in intro.txt using the Tab Key to auto complete and Enter.

Nano: opening a new file.
If you didn't do Alt+F for new buffer intro.txt will end up being pasted into my_help.txt at the cursor position. Do an Alt+U to Undo and try and try again.
Nano: Two files open, use Alt+Left/Right to move between them

You have now two files open with intro.txt being number 2, go Alt+Left to go backwards though the files or Alt+Right to go forward and return to my_help.txt, Cut the last topic on line 47 Working with documents, then do a search for 5: and Paste it in there.

Now to play some more with the Read and Write Out Commands...

This file more_help.txt has more shortcuts so lets add them to your my_help.txt, first Right Click more_help.txt and save it in your nano folder.

Insert from a file

If my_help.txt is open use the Alt+Left/Right to go to it and do a Ctrl+End to go down to the last line, then a Ctrl+R to read in a file and in the File to Insert [from ./] start to type in more_help.txt using the Tab key to auto complete and hit Enter. The contents of more_help.txt will be added.

Nano: Insert text from a file.

If more_help.txt is in another folder such as your Download folder, use Ctrl+T to start a basic File Browser with its own help page. Use your Arrow Keys to select a file or directory and hit Enter to open that file or change to that directory.

Nano has a basic File Browser.

Amend a closed file

If my_help.txt is closed, an alternative is to open more_help.txt and write out the contents of that file to my_help.txt, so try out the following..

Do a Ctrl+R to read a file and Alt+F for a new buffer and Browse or Enter more_help.txt.

When in more_help.txt do a Ctrl+O to Write Out and this time do an Alt+A to Append (add to the end of) and in Filename to Append to: type in or Browse to my_help.txt and hit Enter.

Nano: Append text to a closed file.

Open my_help.txt and you will find the extra commands added. You can also insert a file or selection to the beginning of another closed file using Alt+P Prepend.

Creating Backups

Alt+B and then hit Enter creates a backup of the file you are working on with an ~ added to the end of the filename, leaving you to edit on the original.

If you change the File Name to write and hit Y to Save file under DIFFERENT NAME Nano will close the original file, saving recent changes to your new file and you continue to edit that new file instead.

Text Formats

Text files like everything in computers are coded using binary (zero's and one's) with each individual letter, number, space, special character, etc stored as a byte (8 bits), check out ascii-code.com where you will find that a Uppercase A is 01000001 (a binary number) which can converted to a decimal number 65 or to a hexadecimal number 41.

The first 32 characters in the ASCII-table are unprintable control codes and are used to control peripherals such as printers, two of these characters are used to mark the end of a line of text and they are ..

... and there are three types of text formats that nano can save as, they differ in how the end of a line of text is noted.

1: Linux Format, the default for nano, which is used by Unix/Linux and Apple OS X and higher - lines end with the LF Line Feed Character.

2: DOS Format when in Write Mode the command Alt+D saves a file with the Dos Format which DOS and Windows use - lines end with a CR Carriage Return and then a LF Line Feed Character.

3: Mac Format when in Write Mode the command Alt+M saves a file with the Mac Format which Mac OS version 9 or earlier use - lines end with the CR Carriage Return Character.

There is a interesting article on Wikipedia about the history behind the above and a screen shot to explain it. Inspired by this article I created a three line text document saving it with the DOS Format.

Nano: Append text to a closed file.

I then ran hexdump -C dos.txt to see the underlining ASCII code in hexadecimal form used to create this file:

31 is a number one, 61 is a lowercase a and yes each line ends with a 0d Carriage Return and 0a Line Feed.

Nano: Append text to a closed file.

Now you probably have three or four files open, no bother to you, just bop around them using the Alt+Left/Right or do a Ctrl+X to close some of them.

The next section of commands will come in useful if you ever decide to try some coding so lets jump right in by opening another file!!!