Whoa?! I started typing and then my cursor jumped all over the place.
When I first opened something in vi, I just started typing. And that was frustrating. I couldn’t figure out how to move the cursor, start typing, stop typing, or just quit the darn thing.
This is very common with UNIX text editors, especially those of us who grew up in Windows. Save is not Ctrl+S. There is no mouse, and navigating just doesn’t quite work like we think it should.
Ahh, now I get it
Vi has two modes:
- Command Mode: Default mode when you open vi. Allows you to run commands with simple keystrokes. Pressing “dd” will delete/cut a line. This seems weird but bear with me.
- Insert Mode: What we’re used to. Type as normal. Pressing “dd” will actually type two d’s.
To switch between modes:
- In Command Mode, press i to switch to Insert Mode.
- In Insert Mode, press ESC to switch to Command Mode.
Start with these commands
- :w – “Write”, aka save.
- :q – “Quit”, aka exit vi.
- :wq – Save and quit.
- :q! – Quit without saving.
- i – “Insert”. Switch to insert mode.
- a – “Append”. Switch to insert mode and append/move the cursor to the end of the current line.