Basic Vim editing for beginners

Vim is a Powerful console-based text editor. It is full of features. But in this tutorial we will only see the basic editing with the vi/vim editor. After going through this you will be able to do most of the essential tasks with vim without spending a lot of time for learning all of vim.

before starting you must have vim installed on your computer

1. To install vim in ubuntu OS enter the following command in the terminal

sudo apt-get install vim

2. Let us now create a new file. Type vi followed by the name of file you want to create like shown below. and ofcourse the filename can be anything like example.c, example.txt, etc..

vi example

3. after entering the above command you will see a blank window (shown in image below). Initially we are in command mode.  to add text to the file you need to enter into the insert mode. Press the i key to enter the insert mode (don’t press enter key) and now you can add text to the file.

4. When you have finished adding text, press the ESC key to leave the insert mode and return to command mode. To save the file to the disk and quit vim press :wq from the keyboard

now, lets understand what :wq command means with the following table

 :  to begin a command 
 w   to write/save text to file 
 q  to quit the editor 

Please note that you can enter :w and :q individually also. but combining them into the single command :wq is much easier.

and now you are back to your dollar prompt ‘$’

Editing an existing file will follow exact same process , Lets say we want to edit the file example that we just created. To open it type the command below

vi example
to start editing/adding text press the i key and after editing press :wq just like we did earlier
See more Vim Commnands => HERE

3 thoughts on “Basic Vim editing for beginners

Leave a Reply

Your email address will not be published. Required fields are marked *