Entering and Quitting Vim
To use Vim you either open it with an existing text file or you just type Vim in the Terminal / Command Line
- $ vim ← This will open vim, but it will open with an unnamed file
- $ vim filename.txt ← This will open vim with a named file, or if that file exists already, and you are typing the command where that file exists, it will open that file
Quitting Vim
Vim works in a couple of different modes, mainly it's NORMAL mode, and INSERT mode.
If you hit the i key when you are in NORMAL mode, you will see at the bottom left of your terminal the word —INSERT—
When you're in INSERT mode, you can type text.
To get out of INSERT mode and back to NORMAL mode, you hit the ESC key.
When you're in NORMAL mode (note that when you're in normal mode you won't see text on the bottom left of the screen)
To be able to quit Vim, you need to be in NORMAL mode
- :q ← This will quit Vim and put you back in the Terminal, if you haven't made any changes to the file
- :q! ← If you've made changes to a file and you try doing :q in normal mode, you will get this suggestion. The exclamation asserts that you want to quit without saving.
- :wq ← This will quit on save. Like Michael mentions in the video, this stands for write and quit.
Things to note
When you try to quit on save with :wq in a file that hasn't been named, you will get a 'E32: No File Name' error. So to save the changes to an unnamed file, you can do either:
- :wq filename.txt ← This saves it, names it, and quits vim
- :w filename.txt ← This will save it and name it. After this you can just do :q