Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unix Fundamentals - Part iii vi Editor

Similar presentations


Presentation on theme: "Unix Fundamentals - Part iii vi Editor"— Presentation transcript:

1 Unix Fundamentals - Part iii vi Editor
UNIX III Unix Fundamentals - Part iii vi Editor 4-Sep-98 1 1

2 Unix Editors Unix editors are key to use creatively the computer;
Editors allow to: create & alter text files; format text files; and more. The ex family of editors consists of ex - line editor (replaces ed) edit - trimmed down version of ex vi - visual editor ed - original standard editor. 4-Sep-98 3 3

3 Memory Buffer Files are stored in system’s hard drive;
When using an editor, a copy of the files is pulled into memory (RAM), leaving the original file undisturbed; This copy is stored in a temporary workspace called the buffer (in memory); Changes are made to this copy, not to the original file; To keep the changes, one has to write (w) the buffer onto the system’s hard drive. 4-Sep-98 3 3

4 History of vi vi editor was developed at UC Berkeley, as part of BSD Unix; AT&T System V made vi part of the operating system; Before vi the standard editor was ed; ed was a line-oriented editor. When ex came along, ed became a subset of ex; ex allows the user to work on a full-screen mode. This mode is called visual display (vi). 4-Sep-98 3 3

5 History of vi (cont) When working with ex editor, there are five modes of operation: ex command mode; ex input mode; vi command mode; vi input mode; and vi last line mode. Using vi most likely we use vi command mode & vi input mode. Ocassionally, we will be using last line mode. 4-Sep-98 3 3

6 vi Screen Editor Modes of Operation: 4-Sep-98 3 3

7 vi Screen Editor when vi is invoked, it starts in the command mode. This means that any keyboard stroke is interpreted as a command. in command mode we can: delete words; delete lines; change a spelling error; and more. 4-Sep-98 3 3

8 vi Screen Editor To change to (text) input mode, use the append command (a). This is, press [a]-key. when in input mode, key strokes will be interpreted as text to be stored in the buffer, not as a command; To exit the input mode, use the [Escape]-key; To save the changes in command mode, or the text typed in input mode, we use the write command (w). w saves the entire buffer, or a segment of it. 4-Sep-98 3 3

9 vi Screen Editor Modes of Operation: 4-Sep-98 3 3

10 vi Screen Editor Basic Commands:
Cursor Position: [h], [j], [k], [l], and [Return]; (text) Input Mode: [a], [i], [o], [O]; Leave (text) Input Mode: [Esc]; Delete / Replace: [x], [dd], [r]; Undo Changes: [u], [U]; Save / Quit vi editor: [Z][Z], :[w], :[q][!], :[w][q]; Erase characters: [Delete], [Ctrl][h]. 4-Sep-98 3 3

11 vi Screen Editor Additional vi Commands:
Cursor Position including scrolling, paging, and searching: [Ctrl][d], [Ctrl][f], [Ctrl][b], [Ctrl][u], [e], [b], [G], n[G], [Ctrl][g], /patterm, [$], [0]; Commands to operate on words, lines, sentences, paragraphs: [c], [d], [y]; Abbreviations for words, lines, sentences, paragraphs: [w], [b], [e], [<], [>], [O], [$], [{], [}]; Print buffer: [p], [P]; Join lines: [J]; 4-Sep-98 3 3

12 vi Screen Editor To invoke vi: 4-Sep-98 3 3

13 vi Screen Editor 4-Sep-98 3 3

14 vi Screen Editor When calling vi, it responds by displaying on the screen the contents of the file, followed by a series of tildes (~); vi starts in command mode; Cursor is positioned at the beginning of file (upper left-hand corner of display); To leave vi, type the following sequence: [Esc][:][w][q] [Return] or [Esc][:][w] [Return] :wq stands for write & quit; :w stands for quit. 4-Sep-98 3 3

15 4-Sep-98 3 3

16 vi Screen Editor Cursor Movement: Use the [arrow keys], or
[h]: left move, same line; [l]: right move, same line; [k]: cursor up one line; [j]: cursor down one line; [Return]: position cursor at beginning of next line down. 4-Sep-98 3 3

17 vi Screen Editor (text) Input Mode:
To start typing text, use any of the following commands: [a]: appends; [i]: insert; [o] and [O]: open. Press [Return] to start a new line. When typing use the [Backspace] or [Delete] keys to backup and correct mistakes. 4-Sep-98 3 3

18 vi Screen Editor Wraparound
The length of a line on the screen may not correspond to its actual line in the editor; A line longer than 80 characters (typically) may show on the screen as two lines, but vi recognizes it as a single line; Solutions: Hit [Return]-key before the eightieth character; In command mode, type :set wrapmargin=nn :set wm=nn nn is a number representing margin size. 4-Sep-98 3 3

19 vi Screen Editor Use of the four (text) input modes:
[a]: enters whatever is typed after the cursor, pushing the rest of the line to the right; [i]: enters whatever is typed before the cursor, pushing the rest of the line to the right; [o]: opens a new line below the cursor & places the cursor at the beginning of the new line; [O]: opens a new line above the cursor & places the cursor at the beginning of the new line; 4-Sep-98 3 3

20 vi Screen Editor Deleting & Changing Text:
All these commands are made from the command mode, and vi stays in command mode after they are executed; Use [Esc]-key if not in command mode; [x]: erases the character under the cursor; nn[x]: erases nn-1 characters to the right of the cursor, and the character under the cursor; [d][d]: deletes the line where cursor is positioned; [r]char: replaces the character under the cursor by the character char. 4-Sep-98 3 3

21 vi Screen Editor Undoing Changes:
These commands undo what it has been just done; [u]: undo the last change. Issue only in command mode; if a line has been deleted using [dd], press [u] to recover the line; if [i] is used to insert the word mush in a line, [u] will remove the word (we must return to command mode). [U]: undo all the changes made on the current line. 4-Sep-98 3 3

22 vi Screen Editor Exiting vi editor:
[Esc][Z][Z]: writes the contents of the buffer onto disk for permanent storage. Uses the filename that it was used to enter vi; [Esc][:][w][q]: w stands for write. and q stands for quit. Similar to [Esc][Z][Z]; [Esc][:][q][!]: quits vi, and discards the changes made to the temporary buffer. 4-Sep-98 3 3

23 vi Screen Editor Cursor-positioning Commands
[b]: moves the cursor to the beginning of a word; [e]: moves the cursor to the end of a word; [0]: (zero) moves the cursor to the beginning of the current line; [$]: moves the cursor to the end of the current line. Note: with [0] or [$] the cursor does not jump to the next line or above line as it does with the [b] and [e] key commands. 4-Sep-98 3 3

24 vi Screen Editor Screen Scrolling & Paging Commands
[Ctrl][d]: scrolls or pages the cursor down, usually 12 lines at a time; [Ctrl][f]: scrolls or pages the cursor forward, usually 24 lines at a time; [Ctrl][u]: scrolls or pages the cursor up, usually 12 lines at a time; [Ctrl][b]: scrolls or pages the cursor back, usually 24 lines at a time. Note: These commands are appropriate for mid-size text files, where a few scrolls will cover the entire file length. 4-Sep-98 3 3

25 vi Screen Editor Screen Scrolling & Paging Commands
These are commands issue while in command mode; nn[G]: moves the cursor to line number nn; [G]: moves the cursor to the end-of-file; [Ctrl][g]: echoes the line number the cursor is currently on. 4-Sep-98 3 3

26 vi Screen Editor Pattern Search Commands issued while in command mode;
/string [Return]: vi positions the cursor at the first occurrence of string string - forward search; ?string [Return]: vi positions the cursor at the first occurrence of string string - backward search; 4-Sep-98 3 3

27 vi Screen Editor Deletion, Changes & Rearranging Text
Operator + Scope = Command; Example: dd is operator d, and scope d. dw is operator d, and scope w. Operators: [d]: delete text, and stores a copy in a temporary memory buffer; [p]: put(s) text, recovers text from temporary memory buffer; [y]: yanks (copies) text, and places in temporary memory buffer, for positioning elsewhere; original remains unchanged; [c]: change operator; equivalent to delete & insert. 4-Sep-98 3 3

28 vi Screen Editor Deletion, Changes & Rearranging Text Scope:
[e]: from cursor position to end-of-current-word; [w]: from cursor position to beginning of next word; [b]: from the cursor position backwards to beginning of current word; [$]: from the cursor position to end-of-current-line; [0]: from cursor position to beginning-of-current-line; [)]: from cursor position to beginning of next-sentence; [(]: from cursor position back to beginning of current-sentence; [}]: from cursor position to beginning of next-paragraph; [{]: from cursor position back to beginning of current-paragraph; 4-Sep-98 3 3


Download ppt "Unix Fundamentals - Part iii vi Editor"

Similar presentations


Ads by Google