Sunteți pe pagina 1din 5

Search BC Oracle Sites

The vi Editor - Deleting Text


Search

Home
E-mail Us
Oracle Articles

Oracle Training
Oracle Tips
Oracle Forum
Class Catalog

Remote DBA
Oracle Tuning
Emergency 911
RAC Support
Apps Support
Analysis
Design
Implementation
Oracle Support

Linux Tips by Burleson Consulting

Oracle Tips
Got Questions?
KEEP pool deprecated
in 12c
12c Poster Available!
Free AWR Report
Analysis
BEWARE of 11gR2
Upgrade Gotchas!

The vi editor provides commands for deleting or replacing single characters, single or
multiple words, and single or multiple lines of text. Table 9.4 shows some common
delete and replace commands with their associated actions. Remember you need to be
in command mode to use these.
Command
x
r
dw
dd
D
s
cw
cc
C

Action
Delete one character of text
Replace one character of text with the next character
entered
Delete entire word (3dw deletes 3 words)
Delete entire line (3dd deletes 3 lines)
Delete from cursor to end of line
Switch to insert mode after deleting current character
Delete entire word and switch to insert mode
Delete entire line and switch to insert mode
Change (delete and switch to insert mode) from cursor
position to end of line

Table 9.4: Delete or replace text commands


SQL Tuning
Security
Oracle UNIX
Oracle Linux
Monitoring
Remote support
Remote plans
Remote services
Application Server
Applications
Oracle Forms
Oracle Portal
App Upgrades
SQL Server
Oracle Concepts
Software Support
Remote Support
Development
Implementation

Consulting Staff
Consulting Prices
Help Wanted!

Oracle Posters
Oracle Books
Oracle Scripts
Ion

Searching for Text Strings


The vi editor allows the user to search for a text string either forward (down) in the file
or backward (up). It also allows a shortcut for repeating the search. A special search
capability that comes in handy when writing shell scripts is the ability to search for
matching parentheses, brackets, and braces. Table 9.5 below shows some search
commands and their associated actions.
Command
/text
?text
%

Action
Search forward in the file for text
Search backward (up) in the file for text
With the cursor on a parentheses, bracket, or brace
character, you can press the % key to move the cursor to
its matching open or close character

Table 9.5: Search commands and their associated actions


Cutting, Copying, and Pasting Text
Any of the text deleting commands presented earlier work similarly to the cut feature of
Windows in that they place the deleted text in a buffer area for potential retrieval at a
later time. In Windows, the buffer is referred to as the clipboard.
In vi there is a unnamed default buffer and 26 specifically referenced buffers, each
identified by one of the letters of the alphabet (a, b, c, d, etc.). In order to reference
one of the named buffers, the buffer identifier character is preceded with a single open
quotation. So, ?a refers to buffer a, ?b refers to buffer b, and so on.
When one of the delete commands is used, the text is cut from the document and
placed in the default buffer. To retrieve text from the default buffer, the upper case P
command can be used to paste the default buffer before the current cursor line, or the
lower case p command can be used to paste the contents of the buffer after the current
line. Therefore, a 5dd command followed by a cursor movement and a P command
would cut five lines of text and place them before the line where the cursor was moved.
converted by W eb2PDFConvert.com

Excel-DB
Don Burleson Blog

Instead of cutting or deleting text, it is also possible to copy text from a file using the
yank (yy) command. The yank command presents the option of copying text to one of
the specific named buffers. Where yy would copy the current line to the unnamed
default (unnamed), ?cyy would copy the current line to the buffer named c.
The issuance of multiple yank commands to the same buffer without intervening paste
commands will result in buffer overwrites. In other words, the user cannot yank line
five to buffer a, then yank line seven to buffer a and expect to be able to paste both
lines five and seven somewhere. When a user yanks line five, it is placed in buffer a as
requested, but when a command to yank line 7 to buffer a follows, line 7 will overwrite
line five, which is sitting in the buffer. This is one of the reasons for providing multiple
named buffers to use for multiple successive yanks. Table 9.6 shows copy and paste
commands and their associated actions.
Command
yy
?byy
5yy
p
P
?bP

Action
Copy (yank) the current line of text into the default
(unnamed) buffer
Copy (yank) the current line of text into the buffer named
b
Copy five lines of text to the default buffer
Paste the default buffer after the current cursor line
Paste the default buffer before the current cursor line
Paste the contents of named buffer b before the current
cursor line

Table 9.6: Copy and paste commands and their actions


Undo and Other Useful Commands
Table 9.7 shows some additional miscellaneous commands and their associate actions.
Most important may be the u command which will undo the last change that was
made. In most vi editors you can undo several of the most recent commands.
Command
J
Enter
u
U
:r filename

Action
Join the current cursor line with the next line in the file
Split the current line at the cursor position when in insert
mode.
Undo the last change that was made
Undo any changes made to the current cursor line
Read the file named filename and insert it below the
current cursor line

Table 9.7: Miscellaneous commands and their associated actions


vi Reference
For your convenience we have compiled the tables of vi commands together for quick
reference.
Command
a
i
o
A
I
O

Action
Append text to the right of the cursor
Insert text to the left of the cursor
Insert a new line below the current line
Append text to the end of the current line
Insert text at the beginning of the current line
Insert a new line above the current line

Insert Commands
To return to command mode from insert mode use the escape key.
Command
:w
:wq
<shift>ZZ
:w! newfile

Action
Write the file to disk
Write the file to disk and quit the editor
Same as :wq
Write the file to a new disk file called newfile

Write Commands

converted by W eb2PDFConvert.com

Command
h
j
k
l
^
$
b
w
e
G
:n
Enter
ctrl+b
ctrl+f

Action
Move cursor one position to the left (left arrow)
Move cursor one line down (down arrow)
Move cursor one line up (up arrow)
Move cursor one position to the right (right arrow)
Move to the beginning of the current line
Move cursor to the end of the current line
Move to beginning of previous word
Move to beginning of next word
Move to end of next word
Move to end of the file
Move to line n
Move to the first word one the next line
Page backward (up)
Page forward (down)

Cursor Movement
Command
x
r
dw
dd
D
s
cw
cc
C

Action
Delete one character of text
Replace one character of text with the next character
entered
Delete entire word (3dw deletes 3 words)
Delete entire line (3dd deletes 3 lines)
Delete from cursor to end of line
Switch to insert mode after deleting current character
Delete entire word and switch to insert mode
Delete entire line and switch to insert mode
Change (delete and switch to insert mode) from cursor
position to end of line

Delete and Replace Commands


Command
/text
?text
%

Action
Search forward in the file for text
Search backward (up) in the file for text
With the cursor on a parentheses, bracket, or brace
character, you can press the % key to move the cursor to
its matching open or close character

Search Commands
Command
yy
?byy
5yy
p
P
?bP

Action
Copy (yank) the current line of text into the default buffer
Copy (yank) the current line of text into the buffer named b
Copy five lines of text to the default buffer
Paste the default buffer after the current cursor line
Paste the default buffer before the current cursor line
Paste the contents of named buffer b before the current
cursor line

Copy and Paste Commands


Command
J
Enter
u
U
:r filename

Action
Join the current cursor line with the next line in the file
Split the current line at the cursor position when in insert
mode.
Undo the last change that was made
Undo any changes made to the current cursor line
Read the file named filename and insert it below the current
cursor line

This is an excerpt from "Easy Linux Commands" by Linux guru Jon Emmons. You can
purchase it for only $19.95 (30%-off) at this link.

converted by W eb2PDFConvert.com

converted by W eb2PDFConvert.com

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training
reference for use by our DBA performance tuning consulting professionals.
Feel free to ask questions on our Oracle forum.
Verify experience! Anyone considering using the services of an Oracle support
expert should independently investigate their credentials and experience, and
not rely on advertisements and self-proclaimed expertise. All legitimate Oracle
experts publish their Oracle qualifications.
Errata? Oracle technology is changing and we strive to update our BC Oracle
support information. If you find an error or have a suggestion for improving our
content, we would appreciate your feedback. Just e-mail:
and include the URL for the page.

Burleson Consulting
The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services

Copyright ? 1996 - 2014


All rights reserved by Burleson
Oracle ? is the registered trademark of Oracle Corporation.

converted by W eb2PDFConvert.com

S-ar putea să vă placă și