120 likes | 138 Views
vi. ธวัชชัย เอี่ยมไพโรจน์. เรื่องทั่วๆไปของ vi. ถ้าเป็น server ที่ใช้ร่วมกันหลายๆคน อย่างน้อยจะต้องมี vi และ emacs ไว้ให้ใช้ vi commands มีมากมาย แต่ที่ใช้บ่อยมีไม่มากนัก vi พัฒนาขึ้นที่ UC Berkeley โดย Bill Joy ภายใต้ BSD รุ่นแรกๆ โปรดดูที่
E N D
vi ธวัชชัย เอี่ยมไพโรจน์
เรื่องทั่วๆไปของ vi • ถ้าเป็น server ที่ใช้ร่วมกันหลายๆคน อย่างน้อยจะต้องมี vi และ emacs ไว้ให้ใช้ • vi commands มีมากมาย แต่ที่ใช้บ่อยมีไม่มากนัก • vi พัฒนาขึ้นที่ UC Berkeley โดย Bill Joy ภายใต้ BSD รุ่นแรกๆ • โปรดดูที่ • http://www.techfak.uni-bielefeld.de/~joern/jargon/vi.HTML
vi Fundamentals • vi มี 3 modes • Command Mode • Input Mode • Line Mode • ตัวอย่างการเปิด file (ใช้ได้ทั้งในกรณีที่เปิด file ที่มีอยู่แล้วหรือสร้างใหม่) • vi file.c • แป้น Esc จะกลับสู่ command mode เสมอ
Input commands • i --> insert • เริ่มพิมพ์ได้ ณ ตำแหน่งของ cursor ปัจจุบัน • a --> append • เริ่มพิมพ์ได้ ณ ตำแหน่งที่อยู่ถัดออกไปจาก cursor ปัจจุบัน 1 ตำแหน่ง • o --> open • เพิ่มบรรทัดใหม่และเปลี่ยนเป็น insert mode
Commands in Line mode ที่ควรทราบ • :w write • :wq write then quit • :q quit • :w! Force a write • :wq! Force a write then quit • :q! Force a quit • :e! Re-edit a file
Move cursor ใน file: ใช้ลูกศรเลื่อน • h --> left move the cursor left • j --> down move the cursor down • k -->up move the cursor up • l --> right move the cursor right • (number)g --> goto specific line number • 0 --> beginning of line • $ --> end of line
คำสั่ง Cut Copy Paste • yy --> copy (yank) -- copies the current line • (number)yy --> copies the (number) line • dd --> cut (delete) -- cuts the current line • (number)dd --> cuts the (number) lines • dw --> delete word -- cuts the word pointed to by the cursor • x --> delete character -- deletes the current character • D --> delete to the end of line • p --> paste (put) -- paste what is in the clipboard
คำสั่งอื่นๆ • . --> repeate last command • u --> undo • cw --> change word -- do dw then insert • r(char) --> replace the character under the cusor
คำสั่งในการเคลื่อนย้ายตำแหน่งMovement commands • 0 --> beginning of the current line. • $ --> end of the current line. • b --> move to the beginning of the current word. • w --> move to the beginning of the next word. • e --> move to the end of the current word.
คำสั่งในการค้นหา Search commands • /(characters) --> searches the file, from the current line, for the characters specified. (Search to the end of file). • ?(characters) --> same but searches from current line to the top of file.
คำสั่งในการแสดงผลหน้าจอDisplay commands • ^f -- ctrl-f --> page forward. • ^b -- ctrl b --> page backward • ~ --> changes the case of the character under the cursor. • ^v(char) --> use for insert special meaning character.
คำสั่งพิเศษ Advanced Features :.,$s/hi/lo/g • .,$ --> from current line to the end of file. • s --> substitute (search and replace). • /g --> global -- all “hi” to “lo” in file.