|
A chapter on working with SLES would not be complete without a discussion on one more important topicediting text files. Although editing text files may not sound like a difficult subject, common tools used when editing text files under Linux tend to be rather cryptic. Devoting some space in this chapter to help clear up confusion in this area should make first-time administrators much more comfortable and effective with any task involving text editing. The vi UtilityIt is possible to use graphical text-editing tools under SLES. Many such tools are easily available in both the KDE and GNOME graphical environments. However, a reliance on graphical editors (such as Kate or Gedit) also produces a dependence on a graphical environment. This graphical environment is often not running on a SLES machine. Also, when using a remote shell for SLES administration, graphical tools require tunneling X over SSH. Rather than enabling this tunneling or always using a graphical session on the server, learning and using a command-line editor is more effective and a better solution for the long term. As in the graphical environment, several command-line text editors are available. Among the choices for command-line editors are pico, emacs, and vi. Pico and emacs are both powerful text-editing utilities that offer several appealing qualities. However, these utilities are not always available on SLES installations. The vi utility is the only text-editing utility that is nearly guaranteed to be available with any Linux installation. NOTE The vi utility on SLES is actually the Vi IMproved, or vim utility. As vim is designed to be compatible to vi, it is still commonly referred to as vi. The vi utility is an extremely powerful text-editing utility. Unfortunately, the almost limitless capabilities of vi have also caused its usage to become fairly cryptic and challenging for new users. The most important vi concept to understand is that vi operates in a bimodal fashion. Bimodal means that when using vi, you can be in one of two possible modescommand mode or insert mode. The command-mode environment is used for such tasks as performing file operations, copying and pasting text, performing global search-and-replace operations, and working with macros. The insert mode of vi is used for normal text-editing operations. Probably more important than the two modes themselves is the ability to determine what mode vi is currently in! When vi is initially launched, the interface is left in command mode. It is important to understand that direct file editing is not possible in command mode. Text can be copied and pasted, and various actions such as deleting text can still be accomplished, but adding additional text to the file by typing is not possible. In order to add text to the document, you must first switch to insert mode. Insert mode is entered by pressing "i" or one of a few other insert text keys. When you are in insert mode, the bottom of the vi window will display the text " INSERT ". Prior to adding text to the file, be sure you are in the correct mode by looking at the bottom of the window for that text. When you're in insert mode, you can switch back to command mode by pressing the ESC key. Table 3.20 lists some of the commands that can be used with insert mode.
As previously mentioned, the command mode is used to perform file operations, global text operations, and several other possible actions. These operations are either entered via one of several keystroke combinations, or through a special ":" prompt within vi. A few of the possible commands issued via the : prompt are documented in Table 3.21.
Table 3.22 lists keystroke combinations that can be used when in the command mode of vi.
TIP For a great introduction to vi, execute vimtutor from a command prompt and follow the instructions. Upon completion of the tutorial, most important vi commands should at least be a little more familiar when you need to execute them again! These three tables of vi commands have just barely scratched the surface of what vi is capable of. Although it may seem challenging, the most effective way to learn vi is by using it. When you are proficient with the commands outlined here, enter :help from the command mode of vi for more usage information. |
|