Through this article, we will learn about vim commands. vi is an advanced plain text editor that is run through the command line to edit and create files in Unix-based operating systems. Through the vim commands article, we will try to clear you all the questions and doubts related to the vim text editor.
vim is an advanced version of vi. The vim text editor is the best way to edit and configure all plain text files in Linux. Vi editor is also known as a visual editor.
Install vim package in the system
The package of vi is already installed in a Unix-based operating system, if you want to use vim in Linux, then you can install it with the following command.
[root@simi ~]# dnf install vim -enhanced -y
Install Vim package in /linuxCentos 7
[root@simi ~]# yum install vim -enhanced -y

How to Use vim commands
It is very easy to use vi and vim text editor in Linux, for that first you have to open the terminal and type vi filename.
If you want to use vim to improve the version of vi then you have to type the vim filename. In this text editor, you cannot use the mouse, you will have to use the command only with the help of the keyboard.
# vim filename

Insert the matter in the file
As soon as the file is created with vim or vi text editor, a sign of ~ will appear at the beginning of the file, it means that this line is unused and you can write your matter here and at the bottom of the file you will see the name of the file. The name with which you have created your file.
We discussed Basic three mode:
NORMAL MODE :By defaults vim stated in Normal mode Other modes can be accessed from normal mode only.
INSERT MODE: In this mode, anything can be written to the file. To write something in insert mode press o, Esc+i, Esc+s, Esc+a, and insert the key from your Keyboard.
COMMAND MODE: This mode is for executing commands at the bottom of the editor, To switch from normal mode to command mode type: then type the command For example wq.
To write something in the file or edit the file, you have to use the insert mode, for that, you press one of them o, Esc+i, Esc+s, Esc+a, key from the keyboard.

OR
write vim in the terminal and hit enter the press ESC button from keyboard +: e and create and save a file in your desire location.

:w Or : write | The file will be saved but you cannot exit |
:wq | save and exit from the file |
force:Â ! :w! :q! | You can forcefully save the file by putting the exclamation mark and can also exit from the file. |
: x | save and exit from the file |
:q! | forcefully exit from the file |
:wq! | forcefully save and exit from the file |
:up OR :update | The file will be saved but you cannot exit |

Save And exit from file:
If you want to save and exit from file, you can also use đŸ˜¡ instead of :wq

Basic Navigation
From the picture given below, you can learn to use some navigation keys, like if you want to move one character down in the file, then you can use the down navigation key or the j character.
if you want to move one character up use the k character from the keyboard Similarly, use h to Move one character left, and for the right use the L key from the keyboard.

Navigate to Top and Bottom of the File:
If you want to edit a large file in vim and you want to go from top to bottom or bottom to top, then you can use the shortcut key.
:0 (zero) | go to top of the file |
gg | go to the top of the file |
1g | go to the top of the file |
G | go to the bottom file |
:$ | go to the bottom of file |
: line number | go to the particular line number |
Search Word and Character in the file:
If you want to search any word or character in a file using the vim text editor, then you should use some of the search options given below.
:/character | Search character in the file |
:/word | search word in the file |
Search Character in file:
:/ f
To search a character in a file :/ After you write the name of the character you want to search in the file as you can see in the screenshot below we have searched the f character in the file.

Search word In the File:
:/ option
To search a word in a file :/ After you write the name of the word you want to search in the file as you can see in the screenshot below we have searched the option word in the file.

Display Line number in open file.
: set nu or: set number | display line number in file. |
If you open the file in vim, you will not see the line number. If you want to show the line in the file with the number, then you have to use the: set nu or: set number command.
It is very easy to use, for this you have to come to COMMAND MODE. you want to go to the command mode, you have to press the ESC key from the keyboard, then type the command: set nu or: set number and enter. Your entire file will appear with line numbers.

Hide Line Number :
:set no number or : set nonu : hide line number.
As we have seen above how to set line number in file and if you want to hide line number from file then you have to use :set no number or : set nonu : hide line number command. For example you can see the below screenshot
COPY, Cut, AND PASTE FILE MATTER
:Â y | copy |
:Â yy | copy a line |
:Â p | paste |
:Â d | cut |
:Â dd | cut a line |
The line number from which to copy and cut the file move the cursor to that point and press <ESC> line No + yy (for copy text), or <ESC> line No + cc ( for cut text )
Move the cursor to that point where you want to paste the cut or copy matter press ‘p‘ for Paste whatever has been copied.
DELETE Some LINES :
To delete a line number in the Open vim file, move the cursor to that line and press continue dd.To delete multiple lines press <ESC> +Line number + dd
<Esc>+line number+dd
Create Password Protect Text Files through vim commands
if you want to Create Password Protected file in Linux/Centos/MacOS. first Open Linux Terminal through the system Dash or press Ctrl+Alt+T from Your Keyboard.
To create a password protected file, follow the below command.
[root@simi ~] vim -x filename
When creating a password-protected file with the above command, the -x switch Indicating that you are protecting the file with a password.
Warning: Using A weak encryption method; see: help ‘cm’ Enter encryption key : ******* Enter same key again : ******

Enter Password and Confirm password, without password you can’t read file content. every time need a password to open the file.
Use the following command to open a password protected file every time you put the password in the file .
[root@simi ~]# vim filename
Conclusion
These Tutorials We learned about vim commands in Linux with examples Step By steps hope that now you are understood the vim text editor. If you have any doubt regarding the vim command then you can give your advice and also ask the question via comment.
- What is a Blog? Uses, History, Types, and How It Works
- How to Choose Right Pen Drive: Storage, Speed, Security & More
- Difference Between Linux and Unix : Major Differences
- Difference Between Linux and Windows
- Windows Commands Every User Should Know
The Main Difference Between MP3 and MP4
Pingback: How To Install And Configure FTP Server - SIMITECH
Pingback: How To Install And Configure FTP Server in Centos 8
Pingback: install-and-configure-DHCP-server in Centos 8 by siyaram kaithal
Pingback: how-to-install & Configure SSH-server-in-centos-8-step-by-step
Pingback: INSTALL AND CONFIGURE NGINX HTTP SERVER IN CENTOS 8
Pingback: How to Install And Configure Apache Http web Server in Centos 8
Pingback: Learn Basic command in Linux/Centos/Ubuntu step by step