Header AD

Beginners Guide For Vim Editor With 15 Examples

Beginners Guide For Vim Editor With 15 Examples

Beginners Guide For Vim Editor With 15 Examples
Beginners Guide For Vim Editor With 15 Examples 

Beginners Guide For Vim Editor With 15 Examples 

What is Vim text editor?

Vim is an open source text editor. It comes with hundred of features.I have been using vim for 3 years and I am still learning it's damn powerful and configurable.
Vim editor can be little difficult to learn at the beginning.But trust me you will not regret it.
Vim is probably the most used text editor for editing plain text files.Vim is the highly recommended text editor and most popular as well.Vim is an advanced editor you can so do much with vim.
Vim is not just for editing configuration files, composing file/emails etc.It is programmer's editors.If you are s programmer and looking for good editor Vim is the answer.It is a complete IDE.

In the article we will cover Vim's basics once you get comfortable with Vim then you will explore Vim by yourself.

VIm works with modes. There are two modes :
  • Insert Mode
  • Command Mode

Command Mode

Vim starts with command mode by default. Command mode is used for performing tasks like saving files, executing commands, insert, delete, append, cutting, pasting finding and replacing texts etc..

Insert Mode

With insert mode you can insert text into file. Vim always starts with command mode so if you want to insert text then you have press i .
Lets do it practically.Open your terminal and type vim
root@seven:~# vim
Go to the insert mode type i now you can start type texts.
Once you are in insert mode then you will --INSERT-- at the bottom.
insert mode enables

Back to command mode

Simply press esc from your keyboard.

Save a file

Now lets say you have composed a text file and want save it.First you have switch back to command first so press esc.
Now write :w [file name] and hit enter.
-w is for writing into file and you must give a file.

:w textfile

Quiting Vim editor

Again you have to switch back to command mode by pressing esc.And type the following:
:q!   is for quitting without saving the file.
:wq textfile
It does 2 things at the same time firstly your file will be saved under the name textfile and then it quits vim editor.

cut command

Again you have to switch to command mode in order to execute commands. cut command for Vim is dd type dd twice and it will cut current line.

paste command

To paste out simply type character p

Copy command

press yy twice your current line will be copied.

Delete a single character

x deletes the current line's single current.

Delete word

dw deletes complete word.
dd deletes current line.
7dd deletes seven lines.

Find / search vim command

With command mode[Esc] you can find words inside the file .File must be open inside vim .
Syntax is simple just type forward slash / and and the word you are looking for.

Search and replace

:1,$s/python/java/g : This command will search for string python inside your directory and eventually will replace with java.In this way you can search everything .

So above are the Beginners Guide For Vim Editor With 15 Examples. Hope you like this article, keep on sharing with others too. Also, share your experience with us in a comment box below.

No comments