When learning to utilize a new utility in any operating system, there are several basic hacks that you should master to use that program effectively. These hacks will not necessarily turn you into a pro with that utility, but they will ensure that you never get stuck doing the tool’s essential operations. Because the Linux operating system has a command-line interface, most operations are done via commands (CLI).
VIM application is a top-notch text editor that you may download for free. It is a free and open-source text editor that runs on all major platforms with much functionality and support from the programming community. The VIM text editor also offers several useful commands that you should master to get the most out of it. This article will go through the top 25 vim commands that you can use to get the most out of this text editor.
Installing Vim editor
This is the most important step since you won’t be able to run the commands until you first install the vim editor, and you can do that by typing.
$sudo apt install vim
- Insert Mode
If you plan to write anything on the vim editor, you should be on the insert mode for that. You can do that by typing the letter “i” on the main interface of the vim editor. The keyword “INSERT” will be displayed at the bottom, which means you can write anything on the editor now.
- Normal or Command mode
This mode is super useful if you want to change the text you have written in the text mode. You can switch to this mode by pressing the “ESC” key from the keyboard.
After the installation of the vim editor, you can open it by typing.
- Quit Mode
If you planning to quit or exit the vim editor then you can do that by typing :quit or :q in the vim editor
- Quit mode without saving
If you want to quit vim editor without saving your progress, then you can do that by typing.
- Quit mode with saving
If you are planning to quit the vim editor and want to save your progress and changes, you can do that by typing.
If you are working on the editor and want to save your progress but don’t want to quit it, you can do that by typing.
Navigating in the vim editor is a straightforward process, all you need to do is press the “Arrow keys”. If you are in the normal mode, you can also navigate using the H,J, K, and L keys.
- Deleting Characters
If you want to delete anything from the editor, you can do that by pressing the “x” key if you are in normal mode. If you are in the insert mode, then you can do that by pressing the backspace key.
- Deleting a whole line
The command mentioned above is there to delete the selected text only, so if you are planning to delete the whole line without selection, you can do that by pressing the small d key twice, such as “dd”.
- Deleting all the lines
If you are planning to delete all the lines from the vim editor, then you can do that by typing
- Specific text selection
If you want to select some specific part of the text, you can do that by pressing the small letter “v” below.
- Whole line Text selection
If you want to select the whole line rather than some text from a specific line, you can do that by pressing the capital “V” in normal mode.
- Copy Text
If you have written some text on the vim editor and want to copy some specific lines, you can do that by pressing the small “y” key.
If you want to copy the whole text, you can do that by pressing the capital “Y” key.
- Cut Text
If you want to cut the text rather than copy it, then you can do that by pressing the small “d” from the keyboard
- Paste Text
If you want to paste some text on the vim editor from somewhere else or from the same editor, then you can do that by pressing the capital “P,” or if you want to paste it where your cursor is, then you can do that by pressing the small “p”.
- Undo Text
If you have made a spelling mistake or mistakenly deleted some text, you can recover that by pressing the small ” u” from the keyboard.
- Redo Text
This function is the opposite of undo, which is used to show you the undone changes before by pressing “CTRL + R” from the keyboard.
- Set numbers
If you write lots of commands and text on the vim editor, it would be difficult for you to differentiate between the lines. So, the numbers next to each line make it easy to figure out where we are on the page and where we need to go for editing by typing.
- Finding Text
If you are looking for a specific word in your work that you have performed on the vim editor, then you can do that by typing.
If the word you are looking for appears multiple times, you can go find that word again by pressing the small “n” from the keyboard.
- Word Count
If you want to know that how many words or lines you have written on the vim editor, then you can get this information by pressing the small “g” from the keyboard and then again pressing together” CTRL“ and capital “G”
- Start of the file
If you have written many lines and want to go to the start from some changes and modifications, you can do that by pressing the small “gg” Keyword twice.
- End of the file
Similarly, if you are at the start or in the middle somewhere and want to go at the end of the file, then you can do that by pressing capital “G”
- Find and Replace
For example, in our case, we want to replace “Linux Mint” with “LINUX MINT” so we can do that by typing
:%s/Linux Mint/LINUX MINT/g
If you want to find some specific words and replace them with any other word, you can do that by typing.
- Help Command
The help command is used to provide you with the basic details of any command you are looking for by typing.
For example, if you want to get the details of a copy command as to how you can copy the text, you can do that by typing.
- Open another file
If you want to open any file, you can open a vim editor and type.
For example, we have saved the file with Linumint.txt, now to open this file, you can type
Here the small letter e is specifically used to open a specific file
- Comparison command
This command is used to compare the text between two files that were written inside them.
For that, you need to open a terminal and write the general syntax as.
$vimdiff file_name_1 file_name_2
In our case, we would like to compare two files with Linumint.txt and Linuxmint2.txt so we can write.
$vimdiff Linumint.txt Linuxmint2.txt
In the above image, the red highlighted color shows the text, which is different in both the files and the non-highlighted part shows a similar text.
The vim text editor is a top-notch text editor that you can download for free. It is a free and open-source text editor that runs on all major platforms. Vim is a command-line text editor with a lot of functionality and support from the programming community. This post will go through some of the most crucial vim commands to master if you want to get the most out of this text editor. Simple commands are given precedence over complicated instructions when it comes to using this application. This page contains 25 of the most significant vim editor commands, as the title says.
The Best Linux Tutorials Website