vi and vim - Paiet/Tech-Journal-for-Everything GitHub Wiki

  • vi
    • VIsual Editor
    • Developed for Unix
  • vim
    • Vi Improved
    • Significantly larger feature set
    • Most distros link /bin/vi to /bin/vim
  • Opening a file
    • vi <filename>
  • Command Mode
    • :
  • Insert Mode
    • i
      • Insert at current location
    • I
      • Insert at beginning of line
    • o
      • New line after line
    • a
      • Append to end of word
    • A
      • Append to end of line
  • Closing a file
    • :w
      • Save file
      • :w <filename> to "Save As"
    • :wq or :x
      • Save and exit
    • :q!
      • Exit without saving
  • Deleting text
    • dw
      • delete word
    • :d or dd
      • delete line

vi and vim pt2

  • Copy and Paste
    • y (yank)
      • yy - Copy current line
    • p (put)
      • p - Paste buffer after the current line
  • Moving without arrow keys
    • h
      • Move left
    • l
      • Move right
    • k
      • Move up
    • j
      • Move down
  • Ranges
    • :#,#<command>
    • :1,10d
      • Deletes line 1-10
    • :set number
      • Displays line numbers
      • :set number! to disable
      • vi +# filename opens a file to a particular line
        • vi +12 file.txt
      • To be permanent
        1. vi ~/.vimrc
        2. set number
  • Search
    • /<string> or :s/<string>
      • Search forward for text
      • ? for backward
      • n for next
      • N for previous
    • vi +/<text> filename.txt
      • Opens a file to the first occurrence of a term
  • Search and Replace
    • :s/<findtext>/<replacetext>
      • Replaces text on one line
    • :%s/<findtext>/<replacetext>
      • Replaces text throughout the file
    • :#,#s/<findtext>/<replacetext>
      • Replaces text within a range
⚠️ **GitHub.com Fallback** ⚠️