Download presentation
Presentation is loading. Please wait.
Published byJustin Taylor Modified over 9 years ago
1
Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming
2
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
3 History of VI (vee-eye / vye) ed ex vi vim Bill Joy, 1976 extended visualvi-improvededitor Ken Thompson QED Bram Moolenaar, 1991 ADM3A keyboard layout
4
4 Modes of vi Start End Command Mode move: hjkl Ctr-F Ctr-B delete: d, change: c replace: r, search: /? Command Mode move: hjkl Ctr-F Ctr-B delete: d, change: c replace: r, search: /? ex Mode ewnqr!sg/ map set sh ab ex Mode ewnqr!sg/ map set sh ab Editing Mode aAiIoO ESC : ENTER q ZZ vi is a modal editor.
5
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.c vi *.c vi a.c b.c vi [ab]*.c :wq :q :q! :wn
6
6 vi Commands Once upon a time there were four little Rabbits, and their names were Flopsy, Mopsy, Cotton-tail, and Peter. They lived with their Mother in a sand-bank, underneath the root of a very big fir-tree. from “The Tale of Peter Rabbit” by BEATRIX POTTER cursor e a A i I o O To enter texts
7
7 vi Commands 'Now, my dears,' said old Mrs. Ra bbit one morning, 'you may go into th e fields or down the lane, but don't go into Mr. McGregor's garden: your F ather had an accident there; he was p ut in a pie by Mrs. McGregor.‘ 'Now run along, and don't get into mischief. I am going out.‘ Then old Mrs. Rabbit took a basket and her umbrella, and went through the wood to the baker's. She bought a loaf of brown bread and five currant buns. To move around relaive: hjkl+- page: Ctr-b Ctr-f line: G nG e lh k j 2 lines overlap 2 lines overlap f Ctrl b G 2G + - current cursor
8
8 vi Commands 'Now, my dears,' said old Mrs. Ra bbit one morning, 'you may go into th e fields or down the lane, but don't go into Mr. McGregor's garden: your F ather had an accident there; he w as put in a pie by Mrs. McGregor.‘ 'Now run along, and don't get into mischief. I am going out.‘ Then old Mrs. Rabbit took a basket and her umbrella, and went through the wood to the baker's. She bought a loaf of brown bread and five currant buns. To move around search: / ? find: f word: b e w line: 0 ^ $ mouse click e w b0 /wood $ current cursor ^ e ?go fg
9
9 'Now, my dears,' said old Mrs. Ra bbit one morning, 'you may go into th e fields or down the lane, but don't go into Mr. McGregor's garden: your F ather had an accident there; he w as put in a pie by Mrs. McGregor.‘ 'Now run along, and don't get into mischief. I am going out.‘ Then old Mrs. Rabbit took a basket and her umbrella, and went through the wood to the baker's. She bought a loaf of brown bread and five currant buns. vi Commands To delete x d xdw 2x 3dw dfg d$ dd 1 2 3 4 5 6 7 8 9 10 11 12 13 :12,13d
10
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 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
11 vi Tips vi *.c :r!cal :%!sort :g/debug/p :g/^$/d :.,$w tmp.c :g/\ /p :s/\<./\u&/g
12
12 vi Tips /TBD/;/printf/ :ab Main int main( int argc, char *argv[] ) :ab teh the 5!!fmt :map *s ea’^[bi’^[
13
13 vi Customization ~/.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
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
15 vim : References Vim Home Page http://www.vim.org/http://www.vim.org/ Vim Tips Wiki http://vim.wikia.com/wiki/Main_Pagehttp://vim.wikia.com/wiki/Main_Page Vim Commands Cheat Sheet http://bullium.com/support/vim.htmlhttp://bullium.com/support/vim.html Wikipedia http://en.wikipedia.org/wiki/Vim_(text_editor) http://en.wikipedia.org/wiki/Vim_(text_editor)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.