Resources

vi Editor



vi is a full-screen text editor for Unix/Linux operating systems. 


Modes

vi has two modes of operation:

  • command mode (normal)
  • insert mode

12 Commands

  • Cursor Movement
    • arrow keys (up, down, left, right)

  • Common Commands
    • x - delete character under cursor
    • u - undo last command
    • /string - find character string

  • Ending Edit Session
    • :wq - save changes and quit
    • :q! - quit without saving changes

  • Switch from Command Mode to Insert Mode
    • i - insert to the left of the cursor
    • a - insert after the cursor

  • Switch from Insert Mode to Command Mode
    • <Esc>


Copy and Paste from a Web Page

To copy text directly from a web page into a file named filename use the following commands:

  1. Copy from the selected part into the clipboard using the mouse or <Ctrl>c
  2. Start vi: vi filename<Enter>
  3. Switch to insert mode: i
  4. Paste from the clipboard using the mouse or <Ctrl>v
  5. Switch to command mode: <Esc>
  6. Save and quit: :wq<Enter>

Other Useful Commands

  • Navigation
    • #G - go to line number # (default is the last line)
    • <Ctrl>f - move forward to the next screen
    • <Ctrl>b - move backward to the previous screen
  • Copy and Paste
    • yw - copy from the cursor to the end of word (copies to buffer)
    • yy - copy the current line (copies to buffer)
    • p - paste buffer contents after (or below) the cursor
    • P - paste buffer contents before (or above) the cursor
  • Delete
    • dw - delete from the cursor to the end of word (copies to buffer)
    • dd - delete the current line (copies to buffer)
  • Editing
    • o - open a new line below the cursor
    • O - open a new line above the cursor
    • r - replace character under cursor (eg. rw)
  • Others
    • . - repeat the last command that changed the file
    • n - repeat the last /string (find) command
    • J - join current and following line
  • Most commands can be preceded by number of repetitions (eg. 27dd)

   Printer Friendly Version of this Page print this page     Top  Go Back to the Top of this Page



  Designed by Chris Szalwinski   Copying From This Site   

Creative Commons License