1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
-
Upload
marvin-summers -
Category
Documents
-
view
216 -
download
0
Transcript of 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
![Page 1: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/1.jpg)
1© 2012 John Urrutia. All rights reserved.
Chapter 6
The vi EditorThe vi Editor
![Page 2: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/2.jpg)
2© 2012 John Urrutia. All rights reserved.
TopicsAbout vi
Getting Started: Creating and Editing
Introduction to vi Features
Command Mode – Moving the Cursor
Changing text
![Page 3: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/3.jpg)
3© 2012 John Urrutia. All rights reserved.
TopicsSearching & Substituting for a String
Miscellaneous Commands
Yank Put and Delete
Reading and Writing Files
Setting Parameters
Advanced Editing Techniques
![Page 4: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/4.jpg)
4© 2012 John Urrutia. All rights reserved.
About viStarted out as ed
Line editor – processes commands against a single line
Displays only 1 line at a time
Cumbersome and awkward to use
![Page 5: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/5.jpg)
5© 2012 John Urrutia. All rights reserved.
About viNext out as ex
Line editor – similar to ed
Added vi mode – visual mode
Displayed full screen of data
Provided Additional functionality
![Page 6: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/6.jpg)
6© 2012 John Urrutia. All rights reserved.
About viToday vi
Many variations LINUX uses vimvi has different options than vim
Extremely Powerful
Complex command structure
Works when all else fails
![Page 7: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/7.jpg)
7© 2012 John Urrutia. All rights reserved.
TopicsAbout vi
Getting Started: Creating and Editing
Introduction to vi Features
Command Mode – Moving the Cursor
Changing text
![Page 8: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/8.jpg)
8© 2012 John Urrutia. All rights reserved.
Getting StartedSpecifying a terminal
Normally system will assign terminal attributes
vi takes advantage of terminal capabilitiesSmart vs Dumb
![Page 9: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/9.jpg)
9© 2012 John Urrutia. All rights reserved.
Getting StartedAn editing session
Start vi by typing
…$ vi someNewFileName
vi presents a screen identifying this as a new file.
![Page 10: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/10.jpg)
10© 2012 John Urrutia. All rights reserved.
Indicates file being created
~ are used as place holder
![Page 11: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/11.jpg)
11© 2012 John Urrutia. All rights reserved.
Getting StartedAn editing session
vi has two modeCommandInput
Default is Command Mode
Quit vi without saving by typing in command mode
:q!
![Page 12: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/12.jpg)
12© 2012 John Urrutia. All rights reserved.
The : sets last line mode
The q! says to quit
immediately
![Page 13: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/13.jpg)
13© 2012 John Urrutia. All rights reserved.
Getting StartedCommand Mode
Executes commands based on the keys pressed.
Commands (case sensitive)Cursor movementChange or Delete existing textSwitch to input mode
![Page 14: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/14.jpg)
14© 2012 John Urrutia. All rights reserved.
Getting StartedCommand Mode
Switching to input modei – insert before cursorI – insert at beginning of line a – append after cursor A – append at end of line o – open line below cursor O – open line above cursor
![Page 15: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/15.jpg)
15© 2012 John Urrutia. All rights reserved.
Getting StartedInput Mode
Anything you type is stored in the file buffer and echoed back to the terminal.
Navigation may be available through the arrow keys depending on your terminal
![Page 16: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/16.jpg)
16© 2012 John Urrutia. All rights reserved.
Getting StartedInput Mode
The terminal control keys can be used in input mode to navigate.
Cntl+W, Cntl+H, Cntl+ULimited control
![Page 17: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/17.jpg)
17© 2012 John Urrutia. All rights reserved.
Getting StartedInput Mode
Trouble Getting around?Go back to command mode. It’s easy
Press ESCape keyIf already in command mode terminal will beep/click/flash or otherwise complain
![Page 18: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/18.jpg)
18© 2012 John Urrutia. All rights reserved.
Getting StartedCommand mode Navigation
Arrow key will move
– Move left one character
– Move right one character
– Move down one line
– Move up one line
h
l
j
k
Keyboard
![Page 19: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/19.jpg)
19© 2012 John Urrutia. All rights reserved.
Getting StartedCommand Mode
Deleting Textdd – delete one line at cursord – delete two lines at cursor dw – delete word to the right of
cursor
Oops-- Undo last action – u
![Page 20: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/20.jpg)
20© 2012 John Urrutia. All rights reserved.
Getting Started
I Quit !!!!ZZ – writes the file and exits
:q! – exit Now! No save
![Page 21: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/21.jpg)
21© 2012 John Urrutia. All rights reserved.
TopicsAbout vi
Getting Started: Creating and Editing
Introduction to vi Features
Command Mode – Moving the Cursor
Changing text
![Page 22: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/22.jpg)
22© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
Simple Online Help:help
Similar to info or man for vim
Tutorial vimtutor
![Page 23: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/23.jpg)
23© 2012 John Urrutia. All rights reserved.
Introduction to vi FeaturesThe five faces of vi
ex – command mode
ex – input mode
vi – is a mode of the ex editorCommand modeInput modeLast line mode
![Page 24: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/24.jpg)
24© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
The vi displayThe status line
Error messagesFile status (read-only)
Special characters~ - Identifies un-used area
![Page 25: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/25.jpg)
25© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
The vi displayIf the terminal becomes
unreadable due to scrolling or messages from othersUse the re-draw function
Cntl+LClears screen and re-paints buffer
![Page 26: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/26.jpg)
26© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
Correcting Text as you typeBack-space to the area you
want and change the input mode to replace (Shift R)
Remember commands are case sensitive!
![Page 27: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/27.jpg)
27© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
The Work BufferAllocated when vi is started
Changes are made to the buffer
Overlays the file when saved
Use view for read-only files
![Page 28: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/28.jpg)
28© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
Line Length & File SizeMaximum line length is limited
to the size of memory
Maximum file size is limited to the available drive space
![Page 29: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/29.jpg)
29© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
Split Screens:vi – can support multiple
split screens
Switching between screensCntl+W:e
![Page 30: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/30.jpg)
30© 2012 John Urrutia. All rights reserved.
Introduction to vi FeaturesSplit Screens can be manipulated to the foreground or background:bg – send to background
:fg – rotate to foreground
:display s – display all screens in background
![Page 31: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/31.jpg)
31© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
File LockingWhen vi opens a file it locks it
Other vi sessions will allow others to only read the original file.
How does it do that?
![Page 32: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/32.jpg)
32© 2012 John Urrutia. All rights reserved.
Introduction to vi Features
The same way it can recover an aborted editing session.Creates a .swp file which can
be used to re-cover some or all of the previous editing session
vi –r filename
![Page 33: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/33.jpg)
33© 2012 John Urrutia. All rights reserved.
TopicsAbout vi
Getting Started: Creating and Editing
Introduction to vi Features
Command Mode – Moving the Cursor
Changing text
![Page 34: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/34.jpg)
34© 2012 John Urrutia. All rights reserved.
Cmnd Mode - Moving the Cursor
For one line onlyfchr – find next character
Fchr – find previous character
W – cursor to next word
B – cursor to previous word
![Page 35: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/35.jpg)
35© 2012 John Urrutia. All rights reserved.
Cmnd Mode - Moving the Cursor
) – go to end of sentence
( – go to beginning of sentence
} – go to next paragraph mark
{ – go to prev. paragraph mark
![Page 36: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/36.jpg)
36© 2012 John Urrutia. All rights reserved.
Cmnd Mode - Moving the Cursor
Cntl+B – Back 1 screen
Cntl+U – Up ½ screen
Cntl+D – Down ½ screen
Cntl+F – Forward 1 screen
Hey! BUDF Cntl yourself !#
![Page 37: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/37.jpg)
37© 2012 John Urrutia. All rights reserved.
Cmnd Mode – Changing
Change commandc3w – Change from cursor to end
of 3rd word
Deletes 3 words right of cursor
Sets insert mode
![Page 38: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/38.jpg)
38© 2012 John Urrutia. All rights reserved.
TopicsSearching & Substituting for a String
Miscellaneous Commands
Yank Put and Delete
Reading and Writing Files
Setting Parameters
Advanced Editing Techniques
![Page 39: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/39.jpg)
39© 2012 John Urrutia. All rights reserved.
Search & SubstitutionSearch Command syntax
/expr. – find the next whatever^ – Beginning of line$ – End of line• – Any character\< – Beginning of word\> – End of word[] – Character class definition
![Page 40: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/40.jpg)
40© 2012 John Urrutia. All rights reserved.
Search & SubstitutionSubstitute Command syntax
:addr expr. s/search / replace / options
addr expr.Starting line , ending line
1 – first line of file
• – current line of file
$ – Last line of file
![Page 41: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/41.jpg)
41© 2012 John Urrutia. All rights reserved.
TopicsSearching & Substituting for a String
Miscellaneous Commands
Yank Put and Delete
Reading and Writing Files
Setting Parameters
Advanced Editing Techniques
![Page 42: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/42.jpg)
42© 2012 John Urrutia. All rights reserved.
Join the partyMiscellenous
J –Joins 1 or more lines into one by removing the newline
characters
Cntl+G – Re-displays the status line
•(period) – repeats the last command
![Page 43: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/43.jpg)
43© 2012 John Urrutia. All rights reserved.
TopicsSearching & Substituting for a String
Miscellaneous Commands
Yank Put and Delete
Reading and Writing Files
Setting Parameters
Advanced Editing Techniques
![Page 44: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/44.jpg)
44© 2012 John Urrutia. All rights reserved.
Put that Yank in the Delete BinThe General Purpose Buffer
P or p – copy text from GP buffer to Work Buffer
Y or y – Yank (copy) into GP buffer
D or d – Delete from Work Buffer insert into GP buffer
There are 26 Additional “named” buffers. (“a – “z )
![Page 45: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/45.jpg)
45© 2012 John Urrutia. All rights reserved.
TopicsSearching & Substituting for a String
Miscellaneous Commands
Yank Put and Delete
Reading and Writing Files
Setting Parameters
Advanced Editing Techniques
![Page 46: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/46.jpg)
46© 2012 John Urrutia. All rights reserved.
Read ing, Write ing & RithmaticRead command will copy files into
the addressed line of the Work Buffer. :addr expr. r filename
Write command will write all or part of the Work Buffer to a file.:addr expr. w filename:addr expr. w! filename:addr expr. w>> filename
![Page 47: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/47.jpg)
47© 2012 John Urrutia. All rights reserved.
TopicsSearching & Substituting for a String
Miscellaneous Commands
Yank Put and Delete
Reading and Writing Files
Setting Parameters
Advanced Editing Techniques
![Page 48: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/48.jpg)
48© 2012 John Urrutia. All rights reserved.
Setting ParametersParameters are used to configure vi
at start-up.These can be set or reset at the
command line. Or in lastline command mode.
Common Parameters(no)number, wrapmargin, (no)showmode,
(no)flash, (no)ignorecase,
![Page 49: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/49.jpg)
49© 2012 John Urrutia. All rights reserved.
TopicsSearching & Substituting for a String
Miscellaneous Commands
Yank Put and Delete
Reading and Writing Files
Setting Parameters
Advanced Editing Techniques
![Page 50: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/50.jpg)
50© 2012 John Urrutia. All rights reserved.
Advanced commandsI’ll Edit one more for the road
:e filenameEdits the new file if current buffer is
unchanged
:e! filenameEdits the new file even if current buffer has
changed
Preserves the named buffers
![Page 51: 1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.](https://reader035.fdocuments.us/reader035/viewer/2022081401/56649f4f5503460f94c71f46/html5/thumbnails/51.jpg)
51© 2012 John Urrutia. All rights reserved.
Advanced commandsvi got a new shell
:shSpawns a new shell and then vi sleeps
:! commandExecutes a shell command and returns to
vi
!! commandExecutes a shell command and returns std
output and replaces current line