Download Text Editors - Programming UNIX - Lecture Slides | COMP 4262 and more Study notes Computer Science in PDF only on Docsity!
Outline {^ Editors^ z^ vi^ z^ emacs {^ Reference cards^ z^ http://www.digilife.be/quickreferences/quickrefs.htm
Starting vi {^ ‘vi’ at the prompt {^ ‘vi fileName’ at the prompt^ z^ if fileName exists it allows you to edit it^ z^ if fileName does not exist it createsfileName and allows you to edit it
The two modes of vi
To edit text move the cursor, delete text, search … (editing features) command modetext entry mode
i, I,a, A,o, O,R
Esc
To enter text: any text you enter will be displayed on the screen
- COMP 4/6262: Programming UNIX Lecture 4 Text editors January 30,
- Command Mode { simple editing features z selected by pressing special charactersequences z e.g. ‘dd’ -- delete a line { editing features that require parameters z press the colon (:) key, followed by the command sequence, followed by z e.g. ‘:1,3d’ – deletes lines 1 through
- Range of Lines { Some commands act upon a block or range of lines z To select a single line, state its line number z To select a block, indicate first and last line numbers inclusively,separated by a comma { Special variables z ‘.’ denotes the line number of the current line (where the cursoris) z ‘$’ denotes the line number of the last line of the file { vi allows arithmetic expressions when stating line numbers z ‘:.,.+2d’ – deletes current line and the two lines follow it { examples: z 1,$ z 1,. z .-
Common Editing Features {^ Categories^ z^ Moving the cursor^ z^ Deleting^ z^ Replacing^ z^ Pasting^ z^ Searching^ z^ Searching and replacing^ z^ Saving and loading^ z^ Miscellanous (e.g. quitting vi)
Moving the cursor h^
move left one position
l^
move right one position
j^
move down one line
k^
move up one line Your arrow keys might work (dependson the version of vi and yourterminal)
Deleting text Item to delete
Key sequence character
position the
cursor over the char and then press
x
word^
position the cursor at the startof the word and then press
dw
Line^
position the cursor anywhere inthe line and then press
dd
Current positionto the end ofcurrent line
press^ D block of lines
:
d
Replacing Text^ Item to replace
Key sequence character
position the
cursor over the char, press^ r
, then the replacement char
word^
position the cursor at the startof the word, press
cw , then the replacement text followed by
Esc
Line^
position the cursor anywhere inthe line, press
cc , then the replacement text followed by
Esc
Searching Commands /string
search forward for string ?string
search backward for string^ (from current position) n^
repeat last search N^
repeat last in opposite direction
Searching and Replacing :
s /string1/string z^ replaces the first occurrence string1 withstring2 on each line :
s /string1/string
g
z^ replaces every occurrence of string1 withstring2 on each line (global replacement
Miscellaneous {^ Redraw screen:
Control
{^ Undo:
u
{^ Undo all changes to current line:
U
{^ Join next line with current line:
J
{^ Repeat the last operation:
{^ Execute command in a subshell and thenreturn to vi:
:! command
{^ Execute command in a subshell and readits output into the edit buffer at thecurrent position: :r!command
Customizing vi {^ Use^
:set {^ Display current settings:
:set all
{^ Available settings:^ z^ autoindent^ z^ ignore case^ z^ number^ z^ showmode^ z^ showmatch {^ Example:^ :set autoindent^ :set noautoindent {^ Use .exrc