Top Banner
Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming
15

Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

Dec 13, 2015

Download

Documents

Justin Taylor
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 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

Page 2: Byoung-Jo CHOI Fall 2007 SW Project II Advanced 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

Page 3: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 4: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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.

Page 5: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 6: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 7: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 8: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 9: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 10: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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/

Page 11: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 12: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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’^[

Page 13: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 14: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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

Page 15: Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.

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)