Pratical Implementation of Command in Vim Editor
You can open vim by running vim command on the terminal.
vim
There are some commands given to use the vim editor. You can see all commands, and it’s documentation by help command as follows:
:help
Now to exit type this command
:q!
Now, Let’s Start to use Vim
To open a file in vim editor just write the file name after the vim command in the terminal as follows:
vim filename.txt
Then the file will be opened.
Write into file
In the previous step we have opened the file now, Let’s write some content in to write data we need to go in insert mode. To go into write mode type i. As follows:
i
After going into insert mode you will see INSERT in the status bar. After that, we can write any data in it.
Save and Exit:
We have written the data into a file now the task is to save and exit the file to do that first exit from insert mode by pressing the Esc key. To write a command first type semicolon ( : ) and then type the command wq! or x! (both do the same thing) And then hit ENTER.
:wq!
Exit without saving the file:
To exit from the file without saving the file just use the command q! As follows
:q!
Vim also comes with its own tutorial. You can see this tutorial by command vimtutor into the terminal .
vimtutor
Now vim tutorial will be opened as follows:
Text Editing: Insertion
We have edited some text files before by using the i key. There are Four keys used for the insertion of text. Just type the key into the normal mode in vim.
i -> This key is used to put the cursor before the current position.
a -> This key is used to put the cursor after the current position.
o -> This key is used to put the cursor below the line.
O -> This key is used to puts the cursor above the line.
Motion: Motions provide context to your Operators. These execute the action in a particular way.
Here is a list of some motions
w - until the start of the next word, EXCLUDING its first character.
e - to the end of the current word, INCLUDING the last character.
$ - to the end of the line, INCLUDING the last character.
We can use motion with the d key and with many more keys
Count: Count is the number for which replete the motion for count number. Here is a demonstration of the use of count and motion
To move courser 2 words forward use the following command
2w
Here 2 is the number of counts and w is used for word
To move the cursor 4 lines forward use the following command
4$
Vim Editor in Linux
If you’re new to the world of Linux, one of the first things you’ll encounter is the command line interface. And if you’re going to be working in the command line, you’ll inevitably come across various text editors. Among them, Vim stands out as a powerful, yet notoriously complex, text editor. In this guide, we’ll take you through everything you need to know about Vim, from its basics to more advanced features, to help you get started on your journey with this essential tool.