UNIX COURSE - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

UNIX COURSE

Description:

Input mode enter the text you want, every thing you enter goes to the file, ... Last line mode, you invoke this by entering : colon. ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 14
Provided by: just4
Category:
Tags: course | unix | mode

less

Transcript and Presenter's Notes

Title: UNIX COURSE


1
UNIXCOURSE
  • Issa Mahasneh
  • issa_at_just.edu.jo

2
Lesson 2
  • Editing Files

3
The vi Editor
  • De facto standard UNIX editor
  • Written by Bill Joy in 1976
  • From the word visual
  • The most powerful UNIX editor

4
Invoking vi
vi file1.txt vi file1.txt file2.txt vi
30 file1 vi vi /string file
5
vi Modes
  • Command mode, when vi it starts, it is in command
    mode, lot of commands you can use here such as
    when pressing i for input it will move you to
    input mode just before the current cursor
    location, with upper case I vi will enter input
    mode at the beginning of the current line.
  • Input mode enter the text you want, every thing
    you enter goes to the file, backspace key lets
    you back up, deleting chars as you go, until the
    end of the line.
  • Last line mode, you invoke this by entering
    colon. The cursor will jump to the last line of
    the screen and vi will wait for your command r
    file2 will read file2 into the current buffer
    after the current line.

6
vi Modes
7
Switching to Insert Mode
  • a append text after the char the cursor is on.
  • A append text after the last char of current
    line.
  • c begin a change operation
  • C change from cursor to end of line.
  • i insert before the char where the cursor is on.
  • I insert at the beginning of current line.
  • o open a blank line below the current line.
  • O open a blank line above the current line.
  • R begin overwriting text.
  • s substitutes single character.
  • S substitutes whole lines.

8
Command Mode
  • When you want to change from insert mode to
    command mode, press the ESC key.
  • d deletes words, lines, etc.
  • u undoes the last edit.
  • P pastes -insert- the yanked or deleted lines
    before the current line.
  • p paste the yanked or deleted lines after the
    current line.
  • ZZ quit vi, saving the file only if changes
    were made since last save.

9
Commands Examples
  • 5dw delete five word, starting at the current
    cursor position. If the current line ends it will
    continue with the next line.
  • 7dd deletes 7 lines, starting at the current
    line.
  • c2b changes back two words starting from the
    preceding character for the current cursor
    position. If the current it reached the beginning
    of the line it will continue with the previous
    line.
  • 1G puts the cursor on the first line of the file.
  • 10yy Yanks (copies) the next 10 lines starting
    with current line into temporary buffer.

10
Cursor Movements /Editing Commands
  • 1G moves the cursor to the first line.
  • G move the cursor to the last line.
  • 0 (zero) move the cursor to the first char of
    the current line.
  • Ctrlg or G report the position of cursor in
    terms of line and col .
  • moves the cursor to last char of the line.
  • w moves the cursor forward one word.
  • b moves the cursor backward one word.
  • x delete the char at the cursor position.
  • dd delete the line at the current cursor pos.
  • u undoes the most recent change.
  • r replace the char at the current cursor location
    with what is typed next.

11
Yank and Put
  • y2w yanks two words, starting at the current
    cursor position, going right.
  • 4yb yanks 4 words, starting at the character
    previous to the current position going to the
    left.
  • yy or y yanks the current line.
  • P put the yanked text before the current cursor
    position.
  • p put the yanked text after the current line
  • 5p put the yanked text in the buffer five times
    after the current cursor position.

12
Last Line Mode
  • 5,25w file3 write line 5 through 25 into file3.
  • w file4 write the current buffer into file4, if
    exists will ask you to confirm.
  • !ls temporary suspend vi, execute the shell
    command, when completed vi returned.
  • r filename reads and insert the contents of the
    file filename after the current line.
  • q! Quits vi without saving
  • wq save the buffer and quit.
  • w! filename overwrite file name with current
    text.
  • 7,15d delete lines 7 through 15 in the buffer.

13
Substitute
  • s/john/jane/ substitute the word jane for the
    word john the current line only.
  • s/john/jane/g substitute the word jane for
    every word john on the current line.
  • 1,10s/john/jane/g substitute the word jane for
    the word john on line 1-10.
  • 1,s/john/jane/g substitute the word jane for
    the word john for every word in the entire
    document.
Write a Comment
User Comments (0)
About PowerShow.com