1 / 39

UNIX Editors: vi and Emacs - Creating and Editing ASCII Files

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.

woodsm
Download Presentation

UNIX Editors: vi and Emacs - Creating and Editing ASCII Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter Three The UNIX Editors

  2. Lesson A The vi Editor

  3. Objectives • Describe an ASCII text file • Explain why operating system editors use ASCII files • Create and edit simple documents using the vi editor

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

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

  10. 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

  11. Using the vi Editor In insert mode, every character you type appears on the screen

  12. 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

  13. Using the vi Editor

  14. 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

  15. Using the vi Editor

  16. Using the vi Editor Use the delete commands and the cursor movement keys to edit the text

  17. Using the vi Editor

  18. Using the vi Editor

  19. Using the vi Editor The status line at the bottom of the screen displays information, including line-oriented commands and error messages

  20. Using the vi Editor During text searches, you can replace, too. Use line-oriented commands in ex mode to perform this action

  21. 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

  22. 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

  23. Using the vi Editor

  24. Using the vi Editor

  25. Lesson B The Emacs Editor

  26. 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

  27. 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

  28. 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

  29. Using the Emacs Editor The Emacs editor opens in a GUI, with menus containing command choices

  30. Using the Emacs Editor Notice the extensive command choices within the menu structure

  31. 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

  32. 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

  33. 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

  34. 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

  35. 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

More Related