0
Lesson 4-Mastering the Visual Editor
Overview  <ul><li>Introducing the visual editor. </li></ul><ul><li>Working in an existing file with vi. </li></ul><ul><li>...
Overview  <ul><li>Deleting text from a file. </li></ul><ul><li>Undoing editing commands. </li></ul><ul><li>Creating new fi...
Introducing the Visual Editor  <ul><li>Bill Joy, a student of the University of California, wrote the vi editor. </li></ul...
Introducing the Visual Editor  <ul><li>The vi editor is present on every UNIX environment, uses few computing resources, a...
<ul><li>The command mode allows a user to access a file with basic vi commands. </li></ul><ul><li>The append/insert mode a...
Working in an Existing File with vi  <ul><li>Files are central to the UNIX computing environment. </li></ul><ul><li>The vi...
<ul><li>We can edit the files created by the cat command. </li></ul><ul><li>We can access/open the files by giving the &qu...
Understanding the Visual Editor  <ul><li>Moving around in a file: </li></ul><ul><ul><li>Opening a file in vi allows a user...
Understanding the Visual Editor  <ul><li>Moving around in a file (continued): </li></ul><ul><ul><li>The vi editor interpre...
Understanding the Visual Editor  <ul><li>Moving around in the file (continued): </li></ul><ul><ul><li>The vi editor also p...
Understanding the Visual Editor  <ul><li>Working with text: </li></ul><ul><ul><li>To insert characters to the file, we hav...
Understanding the Visual Editor  <ul><li>Working with text (continued): </li></ul><ul><ul><li>After dd finishes deleting, ...
Understanding the Visual Editor  <ul><li>Working with text (continued): </li></ul><ul><ul><li>The “u” command undoes the l...
Understanding the Visual Editor  <ul><li>Quitting the editor: </li></ul><ul><ul><li>The “wq” command instructs the editor ...
Understanding the Visual Editor  <ul><li>Creating and reading a file in the editor: </li></ul><ul><ul><li>A new file can b...
Navigating Through a File  <ul><li>Using the direction keys: </li></ul><ul><ul><li>The arrow keys and the h, j, k, and l d...
Navigating Through a File  <ul><li>Lowercase “n” or “/” (slash) can be used to instruct the vi editor to search forward, w...
Navigating Through a File  <ul><li>The “w” command can be used to advance the cursor to the beginning of the next word. </...
Navigating Through a File  Moving the Cursor in vi
Navigating Through a File  Moving to a Specific Textual Character in vi
Navigating Through a File  Moving the Cursor by Line Address and Location Display
Navigating Through a File  <ul><li>Two single quotation marks instruct the editor to return to the previous location in a ...
<ul><li>CTRL-F displays the next screen of a text file. </li></ul><ul><li>CTRL-D scrolls down one half screen of a text fi...
Adding Text to a File  <ul><li>The “i” (insert) command starts adding text to the left of the cursor. </li></ul><ul><li>Th...
Adding Text to a File  <ul><li>The “I” command instructs the editor to move the cursor to the beginning of a line and to c...
Avoiding Confusion While Entering Commands to Shell and vi  <ul><li>The “who” command, when executed in a shell, lists the...
Deleting Text From a File  <ul><li>Multiple lines, words, and characters can be deleted by prefacing the delete command wi...
Deleting Text From a File  <ul><li>The vi editor also allows lines to be deleted using the line number addresses. </li></u...
Undoing Editing Commands  <ul><li>The “u” command undoes the last editing change in the file. </li></ul><ul><li>The vi edi...
Creating New Files with the Visual  Editor  <ul><li>The vi filename command is used for creating a new file as well as edi...
Making Changes to the Text <ul><li>The “r” command instructs the editor to replace the character located under the cursor ...
Making Changes to the Text <ul><li>The “R” command switches the editor to the “type-over” mode, wherein each letter typed ...
Making Changes to the Text <ul><li>The “cc” command deletes the text from the current line and moves you from the command ...
Making Changes to the Text <ul><li>The substitute command requires two words to be separated by slashes. </li></ul><ul><li...
Moving and Copying Text  <ul><li>The “yy” command instructs the editor to copy the contents of the line where the cursor r...
Moving and Copying Text  Commands to Move and Copy Text
Moving and Copying Text  <ul><li>Marking a place in the file: </li></ul><ul><ul><li>The “m*” command instructs the editor ...
Moving and Copying Text  The delete, change, and yank commands
Moving and Copying Text  <ul><li>Marking a place in the file (continued): </li></ul><ul><ul><li>The mark command can also ...
Writing a File and Quitting the  Editor  <ul><li>The “w” command can be used for saving a copy of the current file to a ne...
<ul><li>The “w!” command instructs the editor to overwrite the contents of the file if it exists, else creates a new file ...
Summary  <ul><li>The vi is the editor used to create and edit files. </li></ul><ul><li>Vi provides several utilities to ed...
Summary  <ul><li>A user cannot insert data without switching to the append/insert mode. </li></ul><ul><li>The I, a, i, A, ...
Summary  <ul><li>The vi provides various utilities to move, edit, delete, and replace text. </li></ul><ul><li>The :wq is u...
Upcoming SlideShare
Loading in...5
×

intro unix/linux 04

1,952

Published on

vi editor

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,952
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
258
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "intro unix/linux 04"

  1. 1. Lesson 4-Mastering the Visual Editor
  2. 2. Overview <ul><li>Introducing the visual editor. </li></ul><ul><li>Working in an existing file with vi. </li></ul><ul><li>Understanding the visual editor. </li></ul><ul><li>Navigating through a file. </li></ul><ul><li>Adding text to a file. </li></ul><ul><li>Avoiding confusion while entering commands to shell and vi. </li></ul>
  3. 3. Overview <ul><li>Deleting text from a file. </li></ul><ul><li>Undoing editing commands. </li></ul><ul><li>Creating new files with the visual editor. </li></ul><ul><li>Making changes to the text. </li></ul><ul><li>Moving and copying text. </li></ul><ul><li>Writing a file and quitting the editor. </li></ul>
  4. 4. Introducing the Visual Editor <ul><li>Bill Joy, a student of the University of California, wrote the vi editor. </li></ul><ul><li>The UNIX/Linux visual editor is a powerful, fast, command-driven screen editor. </li></ul><ul><li>The vi visual editor is available on all systems and is an essential tool. </li></ul><ul><li>The vi editor allows the movement of cursor to a specific location in a file. </li></ul>
  5. 5. Introducing the Visual Editor <ul><li>The vi editor is present on every UNIX environment, uses few computing resources, and includes many tools. </li></ul><ul><li>Standard UNIX releases include vi, and Linux provides vim, which includes some vi improvements. </li></ul><ul><li>Command mode and append/insert are the two modes of the vi editor. </li></ul>
  6. 6. <ul><li>The command mode allows a user to access a file with basic vi commands. </li></ul><ul><li>The append/insert mode allows a user to insert data characters in a file. </li></ul>Introducing the Visual Editor
  7. 7. Working in an Existing File with vi <ul><li>Files are central to the UNIX computing environment. </li></ul><ul><li>The visual editor is used to create new files and edit existing files. </li></ul><ul><li>The vi editor does not permit text to be added directly when editing a file. </li></ul><ul><li>The “cat” utility can be used for creating a file in UNIX. </li></ul>
  8. 8. <ul><li>We can edit the files created by the cat command. </li></ul><ul><li>We can access/open the files by giving the &quot;vi filename&quot; command. </li></ul><ul><li>The command will open the files in the command mode. </li></ul>Working in an Existing File with vi
  9. 9. Understanding the Visual Editor <ul><li>Moving around in a file: </li></ul><ul><ul><li>Opening a file in vi allows a user to delete, move, copy and paste and save and quit the file. </li></ul></ul><ul><ul><li>A user cannot insert characters while in the command mode. </li></ul></ul><ul><ul><li>The fundamental way to move the cursor in a file is to do it with the direction keys. </li></ul></ul>
  10. 10. Understanding the Visual Editor <ul><li>Moving around in a file (continued): </li></ul><ul><ul><li>The vi editor interprets the h, j, k, and l keys as a command to the move the cursor in specific directions. </li></ul></ul><ul><ul><li>The workstation either flashes or beeps if an attempt is made to move the cursor beyond the existing text. </li></ul></ul>
  11. 11. Understanding the Visual Editor <ul><li>Moving around in the file (continued): </li></ul><ul><ul><li>The vi editor also provides a forward search command for moving the cursor to a specific word in the text. </li></ul></ul><ul><ul><li>The /text is the forward search command for moving the cursor to a specified text. </li></ul></ul><ul><ul><li>The “n” command can be used for locating the next occurrence of a target string specified in the forward search command. </li></ul></ul>
  12. 12. Understanding the Visual Editor <ul><li>Working with text: </li></ul><ul><ul><li>To insert characters to the file, we have to change from the command mode to the insert/append mode. </li></ul></ul><ul><ul><li>The vi editor provides the dd command for deleting an entire line of text from a file. </li></ul></ul><ul><ul><li>The “dd” command even deletes blank lines. </li></ul></ul>
  13. 13. Understanding the Visual Editor <ul><li>Working with text (continued): </li></ul><ul><ul><li>After dd finishes deleting, it remains in the command mode. </li></ul></ul><ul><ul><li>The “x” (x-out) command deletes only a single character under the cursor. </li></ul></ul><ul><ul><li>The “a” command switches the vi editor from the command mode to the append mode and allows text to be entered to a file. </li></ul></ul>
  14. 14. Understanding the Visual Editor <ul><li>Working with text (continued): </li></ul><ul><ul><li>The “u” command undoes the last text change made to the file. </li></ul></ul><ul><ul><li>The ESC key instructs the vi editor to switch from the append/insert mode to the command mode. </li></ul></ul><ul><ul><li>A user can check the mode he is working in with the ESC key. </li></ul></ul><ul><ul><li>The “o” command tells the editor to open a new blank line between the cursor line and the next line in the file. </li></ul></ul>
  15. 15. Understanding the Visual Editor <ul><li>Quitting the editor: </li></ul><ul><ul><li>The “wq” command instructs the editor to write the file and quit the editor. </li></ul></ul><ul><ul><li>The “q” command can be used for quitting the editor if no changes are made to the file being edited. </li></ul></ul><ul><ul><li>The “q!” command instructs the editor to quit without saving the changes made to the file. </li></ul></ul>
  16. 16. Understanding the Visual Editor <ul><li>Creating and reading a file in the editor: </li></ul><ul><ul><li>A new file can be created in the vi editor by specifying the filename with the vi command. </li></ul></ul><ul><ul><li>A file opens in the command mode. Text can be entered by switching to the insert/append mode. </li></ul></ul><ul><ul><li>The “r” or the “read” command locates a file and reads its contents into the current file, starting immediately after the cursor line. </li></ul></ul>
  17. 17. Navigating Through a File <ul><li>Using the direction keys: </li></ul><ul><ul><li>The arrow keys and the h, j, k, and l direction keys, either alone or in conjunction with the number keys, make it possible to move the cursor to any character in a file. </li></ul></ul><ul><ul><li>The “set number” command tells the editor to display the line number on the screen. </li></ul></ul><ul><ul><li>The commands “G” and “:$” instruct the editor to move to the last line of a file. </li></ul></ul>
  18. 18. Navigating Through a File <ul><li>Lowercase “n” or “/” (slash) can be used to instruct the vi editor to search forward, whereas uppercase N or ? (question mark) is used to search in the backward direction. </li></ul><ul><li>The “set ignorecase” command can be used to switch off the case-sensitivity feature of vi’s search mechanism. </li></ul><ul><li>The “set” command can be used to view the environmental features that are currently set. </li></ul>
  19. 19. Navigating Through a File <ul><li>The “w” command can be used to advance the cursor to the beginning of the next word. </li></ul><ul><li>The dollar sign ($) instructs the editor to move the cursor to the end of the current line. </li></ul><ul><li>The caret (^) and the zero (0) move the cursor to the beginning of a line. </li></ul>
  20. 20. Navigating Through a File Moving the Cursor in vi
  21. 21. Navigating Through a File Moving to a Specific Textual Character in vi
  22. 22. Navigating Through a File Moving the Cursor by Line Address and Location Display
  23. 23. Navigating Through a File <ul><li>Two single quotation marks instruct the editor to return to the previous location in a file. </li></ul><ul><li>The display adjustment commands are used to adjust the workstation’s screen display to move forward or backward to a different block or section of code, regardless of its context. </li></ul>
  24. 24. <ul><li>CTRL-F displays the next screen of a text file. </li></ul><ul><li>CTRL-D scrolls down one half screen of a text file. </li></ul><ul><li>CTRL-D scrolls up one half screen of a text file. </li></ul><ul><li>CTRL-B displays the previous screen of a text file. </li></ul>Navigating Through a File
  25. 25. Adding Text to a File <ul><li>The “i” (insert) command starts adding text to the left of the cursor. </li></ul><ul><li>The “a” and “i” commands instruct the editor to move from the command mode to the append mode and start adding text at the cursor position. </li></ul><ul><li>The “O” command is an instruction to open a line above the line where the cursor resides and shift to the append/insert mode. </li></ul>
  26. 26. Adding Text to a File <ul><li>The “I” command instructs the editor to move the cursor to the beginning of a line and to change to the append mode. </li></ul><ul><li>The “A” command moves the cursor to the end of a line and switches the editor to the append mode. </li></ul><ul><li>The I and A command instructs the editor to switch to command mode. </li></ul>
  27. 27. Avoiding Confusion While Entering Commands to Shell and vi <ul><li>The “who” command, when executed in a shell, lists the users currently logged on. </li></ul><ul><li>In the vi’s command mode, it moves the cursor to a specific position and moves over to the append mode. </li></ul><ul><li>In vi’s append mode, the characters are entered directly into the file being edited. </li></ul>
  28. 28. Deleting Text From a File <ul><li>Multiple lines, words, and characters can be deleted by prefacing the delete command with a number. </li></ul><ul><li>The uppercase “D” command instructs the editor to delete the remainder of the line starting from the character under the cursor. </li></ul><ul><li>The “df*” command deletes the text from the cursor to the first character * on the current line to the right of the cursor. </li></ul>
  29. 29. Deleting Text From a File <ul><li>The vi editor also allows lines to be deleted using the line number addresses. </li></ul><ul><li>The d command also allows a comma to be used for specifying a range of lines to be deleted. </li></ul><ul><li>Commands that employ line addresses require the ENTER key to be pressed after the command for execution. </li></ul>
  30. 30. Undoing Editing Commands <ul><li>The “u” command undoes the last editing change in the file. </li></ul><ul><li>The vi editor in Linux allows multiple changes to be undone. </li></ul><ul><li>The “U” command undoes any number of changes made to the current line where the cursor is located. </li></ul>
  31. 31. Creating New Files with the Visual Editor <ul><li>The vi filename command is used for creating a new file as well as editing an existing file. </li></ul><ul><li>The vi makes a buffer copy of a file if it exists, else it starts editing a memory buffer using the new filename. </li></ul><ul><li>A file created in vi can be made executable by executing the chmod command. </li></ul>
  32. 32. Making Changes to the Text <ul><li>The “r” command instructs the editor to replace the character located under the cursor with the very next character typed in by the user. </li></ul><ul><li>It can also be used for breaking up a long line into parts. </li></ul><ul><li>The uppercase “J” command can be used for joining two lines of text. </li></ul>
  33. 33. Making Changes to the Text <ul><li>The “R” command switches the editor to the “type-over” mode, wherein each letter typed replaces the character under the cursor as it moves down the line. </li></ul><ul><li>The “s” command substitutes the character under the cursor with the text typed in by the user until the ESC key is pressed. </li></ul><ul><li>The “cw” (change word) command allows a user to substitute a word or multitude of words for a single word. </li></ul>
  34. 34. Making Changes to the Text <ul><li>The “cc” command deletes the text from the current line and moves you from the command mode to the append mode. </li></ul><ul><li>The “C” command puts the editor into the append mode and allows a user to change part of the line from the cursor position to the end of the line. </li></ul><ul><li>The substitute command, a colon command, is used to exchange one regular expression for another in a file. </li></ul>
  35. 35. Making Changes to the Text <ul><li>The substitute command requires two words to be separated by slashes. </li></ul><ul><li>The “g” at the end of the substitute command is a flag and can be used for replacing all occurrences of the target pattern with the addressed lines. </li></ul><ul><li>The substitute command can also be restricted to lines having specific content. </li></ul>
  36. 36. Moving and Copying Text <ul><li>The “yy” command instructs the editor to copy the contents of the line where the cursor resides. </li></ul><ul><li>The “p” or “P” command is used for pasting a new line in a new location below the cursor line. </li></ul><ul><li>The dd and p commands can be combined to perform a cut and paste operation. </li></ul>
  37. 37. Moving and Copying Text Commands to Move and Copy Text
  38. 38. Moving and Copying Text <ul><li>Marking a place in the file: </li></ul><ul><ul><li>The “m*” command instructs the editor to mark a line of text and assign it a label specified in the *; it can have a value from a to z. </li></ul></ul><ul><ul><li>A single quote character with the label name can be used for moving on to a specific label. </li></ul></ul><ul><ul><li>Vi allows deleting, changing, and yanking of text from the current position to the marked spot. </li></ul></ul>
  39. 39. Moving and Copying Text The delete, change, and yank commands
  40. 40. Moving and Copying Text <ul><li>Marking a place in the file (continued): </li></ul><ul><ul><li>The mark command can also be used for simplifying the tasks of deleting, moving, and copying large blocks of text by marking both ends of the block. </li></ul></ul><ul><ul><li>Marking text is a powerful way to identify lines to delete, move, or copy. </li></ul></ul><ul><ul><li>The move or copy commands can be used for moving or copying a block of text specified using line numbers. </li></ul></ul>
  41. 41. Writing a File and Quitting the Editor <ul><li>The “w” command can be used for saving a copy of the current file to a new file. </li></ul><ul><li>The w or write command can also be used for writing a part or block of text from the current file to a new file. </li></ul>
  42. 42. <ul><li>The “w!” command instructs the editor to overwrite the contents of the file if it exists, else creates a new file for saving the contents of the current file. </li></ul><ul><li>The >> symbol, when specified with the w command, appends the text to the file specified. </li></ul>Writing a File and Quitting the Editor
  43. 43. Summary <ul><li>The vi is the editor used to create and edit files. </li></ul><ul><li>Vi provides several utilities to edit text. </li></ul><ul><li>Append/insert and command are the two modes of the vi editor. </li></ul><ul><li>Files created in the cat command can be opened in vi. </li></ul>
  44. 44. Summary <ul><li>A user cannot insert data without switching to the append/insert mode. </li></ul><ul><li>The I, a, i, A, o, and O commands instruct the editor to add text relative to the cursor position. </li></ul><ul><li>The vi editor provides the change (c), yank (y), and delete (d) operators for text operations. </li></ul>
  45. 45. Summary <ul><li>The vi provides various utilities to move, edit, delete, and replace text. </li></ul><ul><li>The :wq is used for saving and quitting the editor. </li></ul><ul><li>The vi editor facilitates global changes, where the user specifies the target for replacement and the replacement text. </li></ul><ul><li>Linux provides an advanced version of the vi, namely the vim editor. </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×