I just can’t quit you VIM

Editing a file in vim is a process that involves several steps, from opening the file to making changes and saving those changes. Here’s a casual walkthrough to get you started:

  1. Opening a File: First off, to open a file with vim, you can use the terminal or command line. Just type vim followed by the name of the file you want to edit. For example:
   vim example.txt

If example.txt exists, vim will open it for editing. If it doesn’t, vim will create it once you attempt to save.

  1. Switching to Insert Mode: By default, vim opens in normal mode, where key presses are interpreted as commands. To start editing (i.e., inserting text), you need to switch to insert mode. Press i for insert mode, which allows you to insert text at the cursor’s current location. There are other variations like a (append) which starts inserting after the current cursor position, and o (open) which creates a new line below the current one and enters insert mode there.
  2. Editing the Text: Now that you’re in insert mode, go ahead and type or modify the text as you see fit. It’ll feel like using a basic text editor.
  3. Using Commands in Normal Mode: Hit Esc to exit insert mode and return to normal mode, where you can use vim commands to save your work, search text, replace words, etc. For instance:
  • To save: Type :w and press Enter.
  • To search: Type :/searchterm and press Enter.
  • To replace: Type :%s/old/new/g and press Enter to replace “old” with “new” throughout the file.
  1. Saving and Quitting: After you’re done editing:
  • To save changes and exit, type :wq or :x and press Enter.
  • To exit without saving changes, type :q! and press Enter.
  1. Undo and Redo: If you make a mistake, press u to undo your last action, or Ctrl + r to redo.