vi

About vi

  • vi is a screen-oriented text editor originally created for the Unix operating system
  • vi was a visual mode of the ex line editor, hence the name
  • Being screen-oriented means that vi would work in a terminal you would use to connect textually to UNIX like systems (so telnet and ssh would be enough to use it)
  • The most used othe editor nano is not as wide-spread as vi, so learning and using vi is still important as it used to be (at least IMHO.. Y.S )

Using vi

  • the main idea is that you have two working modes:
    • pen up (or command mode)
      • used for various commands
      • get to it by pressing ESC key
    • pen down (writing mode)
      • write test
      • get to it:
        • i (insert)
        • I (Insert text at the beginning of the current line)
        • a (append in current location)
        • A (append to the end of the line)
        • o (lowercase o, open a new line below)
        • O (uppercase O, open a new line in current line, push lines down)
  • Open a new file: $ vi β€” Open or edit a file.
  • Commands:
    • :w β€” Save and continue editing.
    • :wq or ZZ β€” Save and quit/exit vi.
    • :q! β€” Quit vi and do not save changes.
    • yy β€” Yank (copy) a line of text.
    • p β€” Paste a line of yanked text below the current line.
    • o β€” Open a new line under the current line.
    • O β€” Open a new line above the current line.
    • b β€” Go to the beginning of the word.
    • e β€” Go to the end of the word.
    • x β€” Delete a single character.
    • dd β€” Delete an entire line.
    • Xdd β€” Delete X number of lines.
    • Xyy β€” Yank X number of lines.
    • G β€” Go to the last line in a file.
    • XG β€” Go to line X in a file.
    • gg β€” Go to the first line in a file.
    • :num β€” Display the current line’s line number.
    • h β€” Move left one character.
    • j β€” Move down one line.
    • k β€” Move up one line.
    • l β€” Move right one character.