CS155: VIM and Regular Expressions Lecture 5 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CS155: VIM and Regular Expressions Lecture 5

Description:

NFS allows us to access files on many machines transparently. ... with the arrow keys. In command mode we can use the arrow keys plus some other useful keys. ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 16
Provided by: csColo
Category:

less

Transcript and Presenter's Notes

Title: CS155: VIM and Regular Expressions Lecture 5


1
CS155 VIM and Regular ExpressionsLecture 5
2
Review
  • NFS allows us to access files on many machines
    transparently.
  • Permissions control various types of access to
    files and directories.
  • pico is a simple text editor with little
    functionality.

3
VIM Visual Editor Improved
  • VIM is an advanced editor that has a very large
    number of useful editing features.
  • The three basic modes in VIM
  • Command mode,
  • e.g., when you first enter vi, or press escape
  • Insert mode,
  • e.g., when you type one of the following iIaAoO
  • Line mode or Colon mode
  • from command mode, start typing with
  • In insert mode text can be entered and modified.
    In command mode commands are given to VIM.

4
VIM Switching Modes
  • On startup VIM is in command mode.
  • To enter insert mode we can use several commands
  • i insert at cursor position
  • I insert at beginning of line (capital i)
  • a insert after cursor position
  • A insert at end of line
  • o new line below (lower-case o)
  • O new line above (upper-case O)
  • To exit insert mode use Esc.

5
VIM Command Mode
  • In command mode typing takes us to line mode
    and allows us to enter a number of VIMs
    commands.
  • w write file (save)
  • q quit VIM (only if file is saved)
  • q! force quit and dont save
  • wq save and quit
  • We can save the file were editing under a
    different file name by typing w filename

6
Navigating in VIM
  • In Insert mode we can navigate with the arrow
    keys.
  • In command mode we can use the arrow keys plus
    some other useful keys.
  • b, w back a word, forward a word
  • , - goto beginning of line, goto end of line
  • nG goto line n
  • G goto end of file
  • In line mode we can move to a different line
    number
  • 12 - goes to line 12

7
Basic Cut and Paste
  • To delete the current line type dd in command
    mode.
  • To delete a character x
  • To delete an word dw or de
  • To delete to end of line d
  • To paste the deleted text use p

8
Basic Command Structure
  • Many commands in VIM have the structure n
    command object
  • 5w move forward five words
  • 5dw delete five words
  • 10d delete to end of line and 9 more lines
  • 2p paste deleted text twice
  • 12x delete twelve characters

9
Undo and Redo
  • To undo a change, enter command mode and type u
  • To redo your undo type R (Ctrl-R) or redo
  • The undo list only goes back to the last save.

10
Searching for Text
  • To search for a string or pattern enter command
    mode and type /pattern
  • To search for next match type /
  • Search and replace can be carried out by
  • s/pattern/replace/cig

Lines to search
Replace all instances on line. (global replace)
Ignore Case
Confirm
Deciphering lines to search all lines in
file . the current line the end of
the file ., from current line to the end of
the file 15,20 lines 15 through 20
11
Search and Replace Examples
  • s/hello/goodbye/cg search for hello and
    replace with goodbye on all lines in th efile,
    confirm all changes
  • 1,10s/good/bye/ig search lines 1-10 for good
    and replace with bye. Ignore the case of good
  • .,s/hi/hello/ - search from current line to end
    for hi and replace with hello

12
More Details
  • For specifying lines to search
  • Numbers 1,10
  • . current line
  • last line
  • ,- line number plus or minus some amount
  • .5, five lines from cursor to end of file
  • -9, last nine lines

13
Windows in VIM
  • W n split screen horizontally
  • W v split screen vertically
  • W q close current window
  • W arrow move to different window
  • e open a file

14
Regular Expressions A Brief Introduction
  • Often we want to search for a pattern rather than
    a string.
  • Regular expressions allow us to specify certain
    types of pattern.
  • . match any single character (except \n)
  • - match zero or more of the preceeding
    character
  • - match only at beginning of line
  • - match only at end of line
  • match any character in

15
Regular Expressions Examples
  • s/hello/Hello/ - search for hello at end of
    line and replace with Hello
  • s/hmellow//g search for hello,mello,mel
    low, hellow and replace with nothing (delete)
  • 1,10s/Goodbye/Hello/ - search for Goodbye at
    beginning of line and replace with Hello
Write a Comment
User Comments (0)
About PowerShow.com