About Vi
Vi is a text editor built written in C, for Unit/Linux since 1976. It is default for Unix systems.
Over the years since its creation, vi became the de facto standard Unix editor and a nearly undisputed hacker favorite[citation needed] outside of MIT until the rise of Emacs after about 1984.
– Wikipedia1
Why Vi
I have to use Vi when I setup my VPS for web hosting. Vi confuses me a while since I have no prior experience. Over time, I came to realize that using Vi is a must for a developer, so let’s don’t hesitate to jump at it!
We’ll get started by learning some of the basics.
Getting started
First of all, Vi have 2 modes: Command Mode and Insert Mode.
Remember how to switch mode:
- press ‘i’ for Insert Mode
- press “Esc” for Command Mode
3 basic file commands
- :w - save
- :q - quit
- :q! - quit without saving
Move the cursor
When in command mode, the key h, j, k and l can move the cursor, just like your arrow key.
- h - Cursor left
- j - Cursor down
- k - Cursor up
- l - Cursor right
Delete
In command mode:
- x - delete 1 char
- dd - delete 1 line
Difference between ‘backspace’ and ‘x’:
- backspace - works in insert mode. Can only delete chars inserted in current session.
- x - works in command mode. Can delete anything.
Repeat operation
In command mode, input a number then the command, the command with be repeat corresponding number of times. Eg “20dd” deletes 20 lines.
Last word
This definitely is not a thorough tutorial, but it’s enough for basic needs of a system admin. I learn these from the 2 tutorials from unix-manuals
Hope it helps you.