You get a bonus - 1 coin for daily activity. Now you have 1 coin

A Mini Cheat Sheet for vi: How to Use It

Practice



In the past, the standard text editor shipped with every Unix system, be it BSD or Linux, was vi. Thank God this stoner-programmer nonsense has now been replaced by ee (EasyEdit) on FreeBSD and nano on Linux, which also come "out of the box".

However, oddly enough, vi is still included "out of the box" and, worst of all, some software continues to use it as its preferred editor (apparently due to the same kind of stoned programming behind that software). Another case is OSes that ship mega-bare (CentOS 6, for example), without even having nano. And in order to install some editor you can actually use, you sometimes need to edit a couple of config files first. But with what? You end up having to run the hated vi.


Here I've written a super-simple sequence for how to open a file, edit it, and close it in vi. Just to have some way out of the situation when there's no text editor at all on the system.


1) Open it - as usual:

$ vi textfile


2) Move using the arrow keys, or if those don't work:

k - Up
j - Down
h - Left
l - Right


3) Once you've reached the spot you need, use:

x - Delete character
i - Enter "insert" mode
a - Enter insert mode, where characters are placed after the cursor


4) After making changes - press ESC to return to "command" mode.

5) To save - press ":" and type "wq", then press Enter:
:wq

6) If it says that changes have not been saved since the last edit, and you're trying to quit with the ":quit" command, just add "!" at the end to ignore the warning.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "LINUX operating system"

Terms: LINUX operating system