Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.
-
Upload
justin-taylor -
Category
Documents
-
view
225 -
download
0
Transcript of Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.
Byoung-Jo CHOI
Fall 2007
SW Project IIAdvanced Linux Programming
SW Project IIAdvanced Linux Programming
2
Lecture 2: Editing / Text Processing
vi : vim, gvim tutorial, tips and tricks
Emacs tutorial, customization, info
sed / tr / awk regular expressions text processing
OpenOffice, LaTeX Printing
3
History of VI (vee-eye / vye)
eded exex vivi vimvim
Bill Joy, 1976
extended visual vi-improvededitor
Ken Thompson
QEDQED
Bram Moolenaar, 1991
ADM3A keyboard layout
4
Modes of vi
StartStart
EndEnd
Command Modemove: hjkl Ctr-F Ctr-Bdelete: d, change: creplace: r, search: /?
Command Modemove: hjkl Ctr-F Ctr-Bdelete: d, change: creplace: r, search: /?
ex Modeewnqr!sg/
map set sh ab
ex Modeewnqr!sg/
map set sh ab
Editing ModeEditing Mode
aAiIoO
ESC
:ENTER
q
ZZ
vi is a modal editor.
vi is a modal editor.
5
vi Commands
To Begin and End Begin End
To enter texts i : insert texts at the cursor I : insert texts at the beginning of the current line a : append texts after the cursor A : append texts at the end of the current line o : enter texts at a new line after the current line O : enter texts at a new line before the current
line
vi hello.cvi hello.c vi *.cvi *.c vi a.c b.cvi a.c b.c vi [ab]*.cvi [ab]*.c
:wq:wq :q:q :q!:q! :wn:wn
6
vi Commands
Once upon a time there were four l
ittle Rabbits, and their names were Fl
opsy, Mopsy,
Cotton-tail, and Peter. They lived wit
h their Mother in a sand-bank, underne
ath the root of a very big fir-tree.
from “The Tale of Peter Rabbit” by BEATRIX POTTER
cursorcursor
e
aA
i
I
o
O
To enter texts
7
vi Commands
'Now, my dears,' said old Mrs.
Rabbit one morning, 'you may go
into the fields or down the lane,
but don't go into Mr. McGregor's
garden: your Father had an
accident there; he was put in a
pie by Mrs. McGregor.‘
'Now run along, and don't get into misch
ief. I am going out.‘
Then old Mrs. Rabbit took a basket and h
er umbrella, and went through the wood t
o the baker's. She bought a loaf of brow
n bread and five currant buns.
To move around relaive: hjkl+- page: Ctr-b Ctr-f line: G nG
elh
k
j
2 linesoverlap
2 linesoverlap fCtrl
bCtrl
G
2G
+
-
current cursorcurrent cursor
8
vi Commands
'Now, my dears,' said old Mrs.
Rabbit one morning, 'you may go
into the fields or down the lane,
but don't go into Mr. McGregor's
garden: your Father had an
accident there; he was put in
a pie by Mrs. McGregor.‘
'Now run along, and don't get into misch
ief. I am going out.‘
Then old Mrs. Rabbit took a basket and h
er umbrella, and went through the wood t
o the baker's. She bought a loaf of brow
n bread and five currant buns.
To move around search: / ? find: f word: b e w line: 0 ^ $ mouse click e
w
b0
/wood
$
current cursorcurrent cursor
^ e
?go
fg
9
'Now, my dears,' said old Mrs.
Rabbit one morning, 'you may go
into the fields or down the lane,
but don't go into Mr. McGregor's
garden: your Father had an
accident there; he was put in
a pie by Mrs. McGregor.‘
'Now run along, and don't get into misch
ief. I am going out.‘
Then old Mrs. Rabbit took a basket and h
er umbrella, and went through the wood t
o the baker's. She bought a loaf of brow
n bread and five currant buns.
vi Commands
To delete x d
x dw dw
2x
3dw
dfgd$
dd
1
2
3
4
5
6
7
8
9
10
11
12
13
:12,13d
10
vi Commands
Addressing absolute : 1,3d relative :.,+1d marked :’a,.d pattern :/for/,/end/d
Addressing absolute : 1,3d relative :.,+1d marked :’a,.d pattern :/for/,/end/d
Marking: mc Marking: mc Register “a2dd “Zp “d2yy
Register “a2dd “Zp “d2yy
Put Text p P “ap
Put Text p P “ap
Replace / Change r R cw s ~
Replace / Change r R cw s ~
Search and Replace :%s/book/note/gc :1,10s/man/woman/
Search and Replace :%s/book/note/gc :1,10s/man/woman/
11
vi Tips
vi *.cvi *.c
:r!cal:r!cal
:%!sort:%!sort
:g/debug/p:g/debug/p
:g/^$/d:g/^$/d
:.,$w tmp.c:.,$w tmp.c
:g/\<if\>/p:g/\<if\>/p
:s/\<./\u&/g:s/\<./\u&/g
12
vi Tips
/TBD/;/printf//TBD/;/printf/
:ab Main int main( int argc, char *argv[] ):ab Main int main( int argc, char *argv[] )
:ab teh the:ab teh the
5!!fmt5!!fmt
:map *s ea’^[bi’^[:map *s ea’^[bi’^[
13
vi Customization
~/.exrc~/.exrc
set autoindent
set tapstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set autoindent
set tapstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
14
gvim
Multiple windows, Syntax Highlighting, Mouse Support vim: help user-manul vimtutor 6 Modes
Normal: default, ESC Visual: v, V, Ctr-v Select: dragging mouse with left click Insert: aAiIoO Command-line: ! / ? : Ex mode: gQ, or invoking ex
15
vim : References
Vim Home Page http://www.vim.org/
Vim Tips Wiki http://vim.wikia.com/wiki/Main_Page
Vim Commands Cheat Sheet http://bullium.com/support/vim.html
Wikipedia http://en.wikipedia.org/wiki/Vim_(text_editor)