Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

9.2. Editing Text Files

Red Hat 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 9-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 will load into the main editing area as shown in Figure 9-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 will open 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 will prompt 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 will automatically appear 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.

9.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 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 9-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 will allow 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.

 
 
  Published under the terms of the GNU General Public License Design by Interspire