Search our database

How To Use vi Command To Edit Files

When setting up your web server via SSH, you will come across a few incidents where you are required to edit certain text files, be it configuration, HTML or CSS files. For first timers and beginners, it may look new and strange to you, it is actually not that difficult. In this tutorial, we will go through a few basic commands on how to use the built in text editor.

 

After logging into your web server via SSH, you can create a new text document by typing the command below:

vi example

This command will create a new text file named “example”, if there is no another text file of the same name existing in the current directory. If there is an existing text file named “example”, it will open that text file instead.

 

To navigate around the document, use the arrow key on your keyboard.

To enter editing modepress “A”.

To escape editing mode/non-editing mode, press “Esc”.

 

In editing mode;

To create a new line, press “O”.

To delete a new line, press “S”.

To undo the changes, press “U”.

To delete a whole line, press “Esc” to enter non-editing mode and press “D” twice.

To stop editing your document, press “Esc” to enter non-editing mode.

 

To save your document and exit text editor, escape editing/non-editing mode and type the command below, to “write and quit”,

:wq

 

To exit text editor without saving, type

:q

 

There’s a good tutorial available for you to be more proficient at vi editor, install the following package and go through the tutorial guide.

yum install -y vim
vimtutor

 

Affordable but Powerful Cloud Hosting Package

Check out IPServerOne’s Cloud Hosting Packages.
Contact us @ +603-6259-5625 or email @ sales@ipserverone.com

Tags: , , , ,