390 likes | 397 Views
Learn how to create and edit ASCII files using the vi and Emacs editors in UNIX. Understand the basics of file storage, binary digits, machine language, and ASCII representation. Discover the features and commands of both editors and become proficient in creating and editing documents.
E N D
Chapter Three The UNIX Editors
Lesson A The vi Editor
Objectives • Describe an ASCII text file • Explain why operating system editors use ASCII files • Create and edit simple documents using the vi editor
Understanding UNIX Files • Almost everything you create in UNIX is stored in a file • All information stored in files is in the form of binary digits • Binary digits are also known as bits • Bits have two states: 1 (on) and 0 (off) • 0’s and 1’s as a way to communicate with a computer is known as machine language
Understanding UNIX Files • Machine language (or bit combinations) is translated into plain English using ASCII • ASCII stands for American Standard Code for Information Interchange • ASCII uses a byte (a string of 8 bits) to represent keyboard characters such as letters and numbers • Text files contain printable, ASCII characters • Binary files contain nonprintable characters, or machine language
Understanding UNIX Files • Programmers develop source code for their programs as text files which are compiled before being executed • Programmers also create scripts which are files containing commands. Scripts are not compiled, rather executed through an interpreter at run time • Executable Program Files are compiled and interpreted files that can be run on the computer to cause actions to be taken
Using Editors • Editors let you create and edit ASCII files • UNIX normally includes two editors: vi and emacs • vi and emacs are screen editors: they display the text you are creating (or editing) one screen at a time
Using the vi Editor • Called vi because it is visual – it immediately displays on screen the changes that you make to text • It is also modal – works in three modes • Insert mode - lets you enter text • Command mode - lets you enter commands to perform editing tasks • Extended (ex) command set mode - lets you use an extended set of editing commands
Using the vi Editor To create a new file in the vi editor, type vi and the name of the new file at the command prompt
Using the vi Editor • When started, the vi editor is in command mode • In order to insert text, you must issue the “i” command to enter insert mode • You can repeat the line just entered with the repeat command (.) • To edit what you’ve just typed, move the cursor with the various keyboard cursor movement keys
Using the vi Editor In insert mode, every character you type appears on the screen
Using the vi Editor The repeat command repeats the last insertion, or line. Now, edit the new line in order to create the next item
Using the vi Editor • While still in command mode: • To delete text, move to a character and then type “x” • You can undo a command (reverse its effects) by typing “u” • To search for a text pattern, type a forward slash (/), type the pattern, and press Enter
Using the vi Editor Use the delete commands and the cursor movement keys to edit the text
Using the vi Editor The status line at the bottom of the screen displays information, including line-oriented commands and error messages
Using the vi Editor During text searches, you can replace, too. Use line-oriented commands in ex mode to perform this action
Using the vi Editor • Saving a File and Exiting vi • You should always save the file before exiting vi, otherwise changes are lost • To save a file and continue working on it, type the :w (write) command • While in command mode, use the :wq (write and quit) command to save and exit, or the :zz command to exit after saving
Using the vi Editor • In vi, you can also: • Add text from another file • Leave vi temporarily to perform other UNIX tasks, then return to your file • Change your display while editing, such as adding line numbering to help editing • Copy, cut, and paste text to help editing • Print text files • Cancel an editing session
Lesson B The Emacs Editor
Objectives • Compare and contrast the features of Emacs and the vi editor • Become familiar with the most important Emacs editor commands • Create and edit simple documents using Emacs editor
Using the Emacs Editor • More complex than vi, so not as popular, but it is more consistent and most commands begin with Alt or Ctrl key combinations • It is not modal like vi • Supports a sophisticated macro language and lets you extend beyond the Emacs program and read email, for instance • Emacs is reputed to have more features than any other UNIX program
Using the Emacs Editor • Creating a New File in Emacs • Type the Emacs command with the name of the new file after it at the command line • If you are using the GNOME interface, start Emacs by clicking the Main Menu icon, clicking Programs, clicking Applications, and then clicking Emacs
Using the Emacs Editor The Emacs editor opens in a GUI, with menus containing command choices
Using the Emacs Editor Notice the extensive command choices within the menu structure
Using the Emacs Editor To save and exit, perform these key sequences: Ctrl+x and Ctrl+s to save, then Ctrl+x and Ctrl+c to exit
Using the Emacs Editor • Editing an Emacs File • To navigate the cursor location, use the arrow keys, or Ctrl key combinations • Text is inserted by typing • Ctrl+x and then “u” is the undo command • You can cut, copy and paste text • There is a text search feature as well • Emacs lets you format your documents with the word wrap feature
Chapter Summary • Bytes are computer characters stored using numeric code, the numeric code is then formatted to plain English via ASCII, and the ASCII characters are stored in text files • The vi editor is a popular choice among UNIX users to edit text files • In the vi editor’s insert mode, characters you type are inserted in the file • With vi, you initially edit a copy of the file in the computer’s memory and the existing file itself is not altered until saved to disk
Chapter Summary • The Emacs editor is popular as an alternative to the vi editor and is included with UNIX systems, including Linux • Emacs has a powerful command syntax, is extensible, and supports a sophisticated language of macro commands • You start Emacs by typing the emacs command at the command line • You navigate an Emacs file by using cursor movement keys or Ctrl key combinations
Chapter Summary • In Emacs, you can undo your editing changes in sequence, even after you’ve made many changes • In Emacs, you insert text simply by typing it in, plus you have the editing features of copy, cut and paste, as well as text searching features