7.2. Editing Text Files

Red Hat Enterprise Linux includes several text editors, applications that allow you to view and modify plain text files. Plain text files are files that contain text without any font or style formatting applied to it, such as system logs and configuration files.

gedit is a graphical text editor. It can open, edit, and save plain text files. You can also cut and paste text to and from other graphical desktop applications, create new text files, and print files. gedit has a clear and understandable interface that uses tabs so that you can open more than one file at the same time without opening more than one gedit window.

To start gedit, click Main Menu => Accessories => Text Editor. You can also start gedit by typing gedit at a shell prompt.

NoteNote
 

gedit can only be used in a graphical desktop environment.

Figure 7-8. gedit

Once gedit is running, you are presented with a blank editing area. You can begin using gedit immediately or click the Open button to locate the plain text file you want to edit. The file loads into the main editing area as shown in Figure 7-8. You can navigate the text file by clicking and holding the scroll bar on the right edge of the window and moving your mouse cursor up and down; or, use the arrow keys to navigate through the text file line-by-line. Press the [Page Up] and [Page Down] keys to advance the document a page at a time.

TipTip
 

gedit allows you to open multiple text files in one window using separate tabs for each file. If you have a file already open and want to copy text from another file, click Open, choose the file you want to access, and the file opens in a new tab within the gedit window. You can navigate between each file by clicking on the the tab associated with the particular filename.

Once you have modified or written your text file, you can save it by pressing the Save button in the toolbar, or by choosing File => Save from the file menus. If you are writing a new text file, a pop-up window prompts you to name the file and save it in the directory of your choice. If you are editing an existing file, then any changes you make automatically appears in the file the next time you open it. You can also choose File => Save As... to save an existing file under a new name or in a different location, which is convenient if, for example, you are editing a configuration file and you want to test your changes without losing your original configuration.

For more information about gedit, choose Help => Contents from the file menus to access the gedit manual.

7.2.1. Shell Prompt Text Editors

If you are not using a graphical desktop and want to read and modify a text or configuration file, Red Hat Enterprise Linux includes the vi (pronounced vee-eye) text editor. vi is a simple application that opens within the shell prompt and allows you to view, search, and modify text files. To start vi, type vi at a shell prompt. To open a file with vi type vi <filename> at a shell prompt.

Figure 7-9. vi

By default, vi opens a file in Normal mode, meaning that you can view and run built-in commands on the file but you cannot add text to it. To add text, press [i] (for Insert mode), which allows you to make any modifications you need to. To exit insert mode, press [Esc], and vi reverts to Normal mode.

To exit vi, press [:] (which is the vi command mode) and press [q] then [Enter]. If you have made changes to the text file that you want to save, press [:] and type [w] then [q] to write your changes to the file and exit the application. If you accidentally made changes to a file and you want to exit vi without saving the changes, type [:] and then type [q] followed by [!], which exits without saving changes.

More information about using vi can be found by typing man vi at a shell prompt.

mirror server hosted at Truenetwork, Russian Federation.