This post will explain the basic of using vi text editor to edit in linux and example.
Open/Create file with vi editor
You may use vi to open an already existing file by typing
where 'file_name' is the name of the existing file. If the file is not in your current directory, you must use the full pathname.
Or you may create a new file by typing
where 'new_file_name' is the name you wish to give the new file.
Closing and Saving a file
To save the edits you have made:
To quit vi, and discard any changes your have made:
Editing text in vi editor
To insert/edit text in a line:
Position the cursor where the new text should go.
Enter the new text.
Copy and Paste content in vi editor
Press to get back to command mode.
Type yy to copy a line
Type p to paste line
Searching in vi editor
To move quickly by searching for text, while in command mode:
Type / (slash).
Enter the text to search for.
The cursor moves to the first occurrence of that text.
To repeat the search in a forward direction, type
To repeat the search in a backward direction, type
Show line number in vi editor
Press to get back command mod
Type :set nu to show line number
Type :set nu! to hide line number