Linux vim editor
Himanshuz.chd 270004408M Visits (11883)
There are many people out there who use Linux for their daily needs. Linux has almost replaced windows for these people and they tend to agree with the fact that Linux is addictive. Its the sheer power of customization, stability and robustness that has contributed to the success of Linux. For a person using computer for his/her daily stuff, a text editor is a very basic requirement. Same goes with the Linux users, a text editor is the bare minimum requirement for them and most of them tend to use GUI based text editors like gedit. When asked why, people generally reply that it is very easy to use.
There is a command line editor in Linux known as vim. Among the end users, the command line vim editor is not as popular as the other GUI editors. When asked the reason they say that it is very complex and command line based. Well, I agree that vim editor is command line based and may look a bit complex in its first impression but It is a very powerful editor. What is needed is a bit of practice to begin with. For all those who shy away or have never used vim editor. Here is a basic article on vim editor that should get you started on a positive note.
Check if vim is installedBefore proceeding to a basic tutorial, you first need to check whether vim is installed on your machine. Just type the vim command on your Linux console and hit enter. As I have vim command installed, here is what I get when do the same :
If you do not get such screen then probably you need to install it first. For example on debain based systems, you just need to run the following command with root privileges:
apt-get install vim
This should get vim editor installed in your Linux machine.
Linux vim editor examples
1. How to open, write and save
In the very first example, we will discuss how to open a file, write in the file and then save the file using vim editor.
To open an existing or a new file, just type vim followed by the file name. If the file is existing then you will find the text content in the vim editor console window else if the file is new then you will see an empty vim editor window. For example, in the following example, I try to open a new file 'test' :
This should give you vim editor window which should look something like this :
The white window in the image above is the vim editor window. So you see that there is nothing in this window as the file 'test' does not exist yet. At the bottom you can see the name of the file along with the information that this is a new file. This is just an information from the vim editor regarding the file.
Now, to start writing just press the 'i' button on your keyboard. This will change the bottom information to something like :
Once you see the 'INSERT' information at the bottom of your window, this means that the vim editor is ready to accept input from you.
Now, lets write some text in file 'test' through the vim editor window.
Now, hit the enter button from your keyboard and this will save your file.
The above information confirm that the file 'test' has been saved. To close the editor follow
2. Cut, copy and paste using vim editor
Once you understand the basic operations that we discussed in (1) above, the operations to cut, copy and paste is not very difficult to understand.
The cut operation can be achieved through :
The copy (or yank) operation can be achieved through:
The paste operation can be achieved through :
3. Undo and replace operations
The undo and replace operations in vim editor are fairly easy to understand.
The undo operation is achieved through :
The replace operation is achieved through :
So this way the undo and replace operations can be done using vim editor.
Learn a cool trick related to vim editor here