This tutorial guides you through the process of creating and editing text files using two popular text editors in Linux. Most Linux distributions come with Nano, a user-friendly text editor, preinstalled. Alternatively, Vi (or Vim) can be used for editing, but it requires familiarity with various commands and modes.
Steps to Follow
Using Nano

Press Control+Alt+T to open a new terminal window. This shortcut works in most Linux versions.
- You can also launch the Terminal by double-clicking its icon in the Applications list or by searching for terminal in the Dash menu (GNOME).
- Nano, a straightforward text editor, is included in all Ubuntu-based distributions. To install Nano on other distributions, use sudo apt install nano (Ubuntu/Debian) or sudo yum install nano (CentOS/Fedora).
- If you're familiar with the Pico text editor, Nano will be very similar. Unlike Vi/Vim, there's no need to switch between command and input modes.

To start, navigate to the directory where you want your file. Typically, you'll aim for your home directory, accessible upon opening a terminal. If your target directory is a subdirectory, use cd to reach it.
- To view all folders in the current directory (your home directory), type ls and press Enter.
- To access a directory within your home directory, type cd directoryname and press Enter (replace directoryname with the actual directory's name).
- To create a new directory, execute makedir directoryname (substitute directoryname with your chosen name), then use cd directoryname to enter it.
- You CAN create and edit files beyond your home directory, but root access is required.

Type nano filename and hit ↵ Enter. Replace filename with your desired name for the new text file. This action both creates and opens a new text file with that name.
- For instance, to create a file named 'testfile,' type nano testfile and hit Enter.
- Appending '.txt' to your filename can be helpful for clarity.
- If a file with the same name exists in your current directory, this command will open that file instead.

Locate the command list at the bottom of the Nano window. The available commands are displayed at the bottom. To access more commands, enlarge the window by dragging from any corner.
- Commands are prefixed with either a carat (^) or an M. The carat denotes the Control key, while M represents the Alt key.
- For example, ^U is the paste command. Press Control + U to paste copied content.
- M-U is the undo command. Press
- To view all Nano commands, press Control + G.

Begin typing into your file. Utilize the arrow keys to move the cursor.
- You can highlight text using the mouse for copying and/or pasting. To copy, press Alt + 6. Then, navigate to the desired location in the file and press Control + U to paste.

Press Control+O to save the file. Since you've already named your file, no further naming is required. However, if you began a file without naming it (simply by running nano from the prompt), you'd be prompted to enter a name and press Enter to save.
- Avoid using Control + S to save, as it will freeze your terminal window!

To exit Nano, press Control+X. This action returns you to the command prompt.
- You can reopen the previously created file in Nano by typing nano filename, just as you did before.
Introduction to Vi and Vim

To open a new terminal window, press Control+Alt+T. This action will launch a new terminal window in any Linux distribution.
- You can also open a new terminal by double-clicking the Terminal icon in your Applications list, or by searching for terminal in your Dash menu (if using GNOME).
- Vi, one of the oldest Unix-based text editors, has been standardized and improved with Vim, short for 'Vi iMproved.' On most modern Linux distributions, running vi actually launches Vim by default. Both editors share basic commands.
- Vi has a steeper learning curve compared to Nano, but once mastered, it's straightforward to use.

Navigate to the directory where you want to create your file. Typically, you'll want to place the file in your home directory, which is your default location upon opening a terminal window. If you intend to place the file in an existing subdirectory, use the cd command to navigate there.
- To view all folders in the current directory (your home directory), type ls and press Enter.
- To enter a directory within your home directory, type cd directoryname and press Enter (replace directoryname with the actual directory name).
- To create a new directory, use makedir directoryname (replace directoryname with your desired name). Then, enter the directory using cd directoryname.
- You can create and edit files outside your home directory, but root access is necessary.

Type vi filename and press ↵ Enter. Alternatively, you can ensure the file opens in Vim by typing vim filename. The 'vi' command selects Vim as the text editor. Replace filename with your desired name for the new file.
- For example, to create a file named 'sample.text', type vi sample.txt.
- If a file with the same name exists in your current directory, this command will open that file instead.

Press the i key. When you open Vi or Vim, it enters Command mode. Pressing the I key switches you to Insert mode, where you can type your text.
- You'll see -- INSERT -- appear at the bottom of the window.

Type your text. In Insert mode, you can type as usual. Press Enter to move to the next line.

Press the Esc key. This returns you to Command mode. Command mode is where you can save, copy, paste, and quit.
- You can navigate the document using arrow keys in Command mode. Vim also allows arrow key navigation in Insert mode.
- Switch back to Insert mode anytime by pressing the i key.

Type :w and press ↵ Enter. Vi/Vim commands start with a colon. :w saves the file.
- To save with a new name (or if the file is unnamed), use :w filename. For help on commands, type :help and press Enter.

Type :q and press ↵ Enter to exit. This action closes the file and returns to the command prompt.
- To reopen the file, type vi filename or vim filename.
- You can save and quit simultaneously with :wq in Command mode.
Useful Tips
- Remember to save your file before closing to avoid losing any unsaved changes.
- To access the manuals for Vi or Nano, type man vi or man nano at the command prompt.
- Vim offers several advantages over Vi, including syntax highlighting, integrated spell-checking, and arrow key navigation in Insert mode, making it especially useful for coders.