Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology

Similar presentations


Presentation on theme: "Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology"— Presentation transcript:

1 Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn

2 Tran, Van Hoai 2010 Basic VI vi - always available Default editor in UNIX  come along with all UNIXs Original name is Visual Editor  Full screen (on terminal)  Some new variants with advanced operating commands Basic commands implemented in all variants of vi

3 Tran, Van Hoai 2010 Basic VI Operation modes 2 modes  command: receive actions on edited file  insert: insert text into file to exit insert mode UNIX and vi are case-sensitive

4 Tran, Van Hoai 2010 Basic VI Get in & out *vi filenameopen file for editing *:x write modified content and quit :wqas above :qjust quit *:q! quit without writing

5 Tran, Van Hoai 2010 Basic VI Moving the cursor cannot use mouse designed for Qwerty keyboard, can use non-arrow keys *j,k,h,ldown, up, left, right 0, $beginning, end of current line :0 first line of file :$ last line of file :n to line n

6 Tran, Van Hoai 2010 Basic VI Undo *uundo last action toggle the last action cannot go more than one step

7 Tran, Van Hoai 2010 Basic VI Insert and add text put vi into insert mode Press to exit insert mode *i,ainsert text before/after cursor, until hit Aappend text to end of current line, until hit

8 Tran, Van Hoai 2010 Basic VI delete text work in command mode *xdelete single character under cursor * dd delete entire current line D delete the remainder of the line, starting with current cursor position

9 Tran, Van Hoai 2010 Basic VI cut and paste work in command mode yy copy the current line into buffer Nyy copy next N lines p paste the buffer after the current line

10 Tran, Van Hoai 2010 Basic VI search text work in command mode /string search forward for occurrence of string in text ?string search backward for occurrence of string in text :.= returns line number of current line at bottom of screen

11 Tran, Van Hoai 2010 Basic VI save and read files :r filename read file named filename and insert after current line (the line with cursor) :w write current contents to file named in original vi call :w newfile write current contents to a new file named newfile :12,35w smallfile write the contents of the lines numbered 12 through 35 to a new file named smallfile :w! prevfile write current contents over a pre-existing file named prevfile

12 Tran, Van Hoai 2010 Basic VI Replacing patterns (1) CharacterPattern \ turn off special meaning \n reuse the text matched by the nth subpattern previously saved by \( and \). Numbered from 1 to 9 & text match search pattern ~, % reuse previous replacement pattern \u convert first character of replacement pattern to uppercase \U convert entire replacement pattern to uppercase \l, \L same; to lowercase \e turn off previous \u or \l \E turn off previous \U or \L

13 Tran, Van Hoai 2010 Basic VI Example (6) CommandResult s/.*/( & )/ add space and parentheses s/.*/mv & &.old/ ? /^$/d delete blank lines (vi, g/^$/d for all lines) %s/ */ /g turn one or more spaces into one space %s/.*/\L&/ lowercase entire file %s/yes/No/g replace yes to No %s/Yes/~/g replace yes to No (previous replacement) s/\(F\)\(ORTRAN\ )/\1\L\2/g FORTRAN to Fortran

14 Tran, Van Hoai 2010 Basic VI Applications PatternMatched text grab a specific HTML tag [0-9]\{1,3\}\. ???? IP address Email address Valid dates (day-month-year) WeWe, does not match Wee ]*>\(.*?\) [A-Z0-9._%-]+@[A-Z0-9.- ]+\.[A-Z]{2,4}

15 Tran, Van Hoai 2010 Basic VI text processing utilities is NEXT


Download ppt "Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology"

Similar presentations


Ads by Google