150 likes | 306 Views
SW Project II Advanced Linux Programming. Fall 2007. Byoung-Jo CHOI. vi : vim, gvim tutorial, tips and tricks Emacs tutorial, customization, info sed / tr / awk regular expressions text processing OpenOffice, LaTeX Printing. Lecture 2: Editing / Text Processing.
E N D
SW Project IIAdvanced Linux Programming Fall 2007 Byoung-Jo CHOI
vi : vim, gvim tutorial, tips and tricks Emacs tutorial, customization, info sed / tr / awk regular expressions text processing OpenOffice, LaTeX Printing Lecture 2: Editing / Text Processing
History of VI (vee-eye / vye) ADM3A keyboard layout extended editor visual vi-improved QED ed ex vi vim Ken Thompson Bram Moolenaar, 1991 Bill Joy, 1976
ESC ENTER Modes of vi Start Command Mode move: hjkl Ctr-F Ctr-B delete: d, change: c replace: r, search: /? Editing Mode aAiIoO : ex Mode ewnqr!sg/ map set sh ab ZZ vi is a modal editor. q End
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 Commands vi hello.c vi *.c vi a.c b.c vi [ab]*.c :wq :q :q! :wn
To enter texts e vi Commands cursor • 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. o i a A I O • from “The Tale of Peter Rabbit” by BEATRIX POTTER
To move around relaive: hjkl+- page: Ctr-b Ctr-f line: G nG e Ctrl Ctrl 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 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. current cursor 2G k - 2 lines overlap h l b 2 lines overlap j + f G
To move around search: / ? find: f word: b e w line: 0 ^ $ mouse click e 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 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. ?go $ e 0 ^ b w fg current cursor /wood
To delete x d vi Commands 1 2 3 4 5 6 7 8 9 10 11 12 13 '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 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. x dw dw 2x 3dw dfg d$ dd :12,13d
Addressing absolute : 1,3d relative :.,+1d marked :’a,.d pattern :/for/,/end/d vi Commands • Marking: mc • Register • “a2dd • “Zp • “d2yy • Put Text • p • P • “ap • Replace / Change • r • R • cw • s • ~ • Search and Replace • :%s/book/note/gc • :1,10s/man/woman/
vi *.c vi Tips :r!cal :%!sort :g/debug/p :g/^$/d :.,$w tmp.c :g/\<if\>/p :s/\<./\u&/g
/TBD/;/printf/ vi Tips :ab Main int main( int argc, char *argv[] ) :ab teh the 5!!fmt :map *s ea’^[bi’^[
vi Customization ~/.exrc set autoindent set tapstop=4 set softtabstop=4 set shiftwidth=4 set expandtab
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 gvim
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) vim : References