1 / 14

Unix Editors

Unix Editors. Speaker: Li-Wen Chen Date: 2010-07-07. Introduction. line-oriented editor ed ex screen oriented editor ee vi - a screen-based editor used by many Unix users. vi m - Vi IMproved. ed. Starting the ed Editor $ ed [ filename ] [ ] means it is optional

brita
Download Presentation

Unix Editors

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix Editors Speaker: Li-Wen Chen Date: 2010-07-07

  2. Introduction • line-oriented editor • ed • ex • screen oriented editor • ee • vi - a screen-based editor used by many Unix users. • vim - Vi IMproved

  3. ed • Starting the ed Editor • $ ed [ filename ] • [ ] means it is optional • After entering, ed is in command mode. • command mode • allows the entry of commands to manipulate text • a– (append) go to input mode • input mode • puts anything typed on the keyboard into the current file • .– terminate input mode • Commands about quit ed • w– write (save file) • q - quit

  4. Other ed commands • a – append after the specified line • i– insert before the specified line • c – change the specified line • .– the current line • ,or%- the first line • $- the last line • l – list (print, display) • d– delete • u – undo enter the character, and then enter input mode

  5. vi • Starting the VI Editor • $ vi [ filename ] • After entering • command mode • allows the entry of commands to manipulate text • i – (insert) go to insert mode • insert mode • puts anything typed on the keyboard into the current file • Esc – go to command mode • Commands about quit vi • :q – quit the vi editor • :w – write (save file) • :wq orZZ – write and quit • :q! – force vi to quit

  6. Inserting New Text • I – insert from the beginning of the current line • A – append at the end of the current line • a – append after the current cursor position • i – insert before the current cursor position • O – create a new line above the current cursor position • o – create a new line below the current cursor position • Type these characters, and then enter insert mode.

  7. Type Commands • [count] command • command – most commands are one character long • count – a number, any character from 1 to 9 • Ex: 10x • x – delete a characters under the cursor • 10x – delete 10 characters at a time

  8. Moving the Cursor • k - ↑, move the cursor up one line. • j - ↓, move the cursor down one line. • h - ←, move the cursor to the left one character position. • l - →, move the cursor to the right one character position. • ^ - Move the cursor to the first non-whitespace character. • $ - Move the cursor to the end of the current line. • % - Move the cursor to the matching parenthesis or brace.

  9. Moving the Cursor (cont.) • ctrl F • Scroll forwards one page. A count scrolls that many pages. • ctrl B • Scroll backwards one page. A count scrolls that many pages. • ctrl D • Scroll forwards half a window. A count scrolls that many lines. • ctrl U • Scroll backwards half a window. A count scrolls that many lines. • G - Go to the line number specified as the count. If no count is given, then go to the end of the file. • gg - go to the beginning of the file

  10. Edit • r -replace one character under the cursor. • x - delete character under the cursor. • ~ - Switch the case of the character under the cursor. • u - undo the last change to the file. • d^ - delete from current cursor position to the beginning of the line. • d$ - delete from current cursor position to the end of the line. • dw - delete from current cursor position to the end of the word. • 3dd - delete three lines from current cursor position downwards. • y (copy) and p (paste) are similar to d.

  11. Search and Replace • / - Search the file downwards for the string specified after the /. • ? - Search the file upwards for the string specified after the ?. • n - Repeat the last search given by '/' or '?' • N - Repeat the last search given by '/' or '?‘, but in opposite direction • < > • For example: /\<the\> should find only word the, but not words like these: there and other. • :s • . – current position • $ - the last line • for example: • :1,$ s/buffer/BUF/ from first line to last line • :.,$ s/money/Money/g from current line to last line

  12. Other useful vi commands • << • Shifts the current line to the left by one shift width. • >> • Shifts the current line to the right by one shift width. • :set autoindent or :set ai. • To unset it, you can type :set noautoindent or :set noai • :set nu • :set nonu

  13. Exercise • 打開vi editor, 輸入15行:Today is a good day. • 下面的動作全部在command mode完成: • yy是複製游標所在的一整行,要怎麼只複製從”a”這個單字之後的文字? (see p.10) • 第一行從good開始改成全部大寫 • 把第5到第10行向右縮排(用法可參考:s, p.11) • 11行到最後一行,最後一個單字day替換成Wednesday.

  14. Reference • $man ed • Mastering the VI editor

More Related