What is Vim?
VIM text editor Comes with Linux, BSD, and macOS is the Unix text editor Vim. Despite having a graphical user interface, it is a simple program that can operate on a terminal, which contributes to its reputation for speed and power. The primary reason for this is that it can be operated completely with a keyboard and no menus or mouse.
The following five factors, in my opinion, justify using Vim:
It is all around us. It's not necessary to consider teaching a novice editor how to use several boxes.
It can be scaled up quite well. You can use it just to make changes to configuration files, or you can use it as your main writing forum.
Its memory footprint is small.
It is centered on commands. You may accomplish difficult operations connected to text with a few commands.
It is highly configurable and uses simple text files to store its settings.
sudo apt-get install vim
Why Use Vim?
Vim is the fallback editor by default in all POSIX systems. Regardless of whether you have booted into a basic system repair environment, are unable to access any other editor, or have just installed the operating system, Vim is undoubtedly open. Even while you can use different tiny editors on your systems, including Jove or GNU Nano, Vim is almost universally installed on other platforms.
To put it briefly, I believe that proficiency in Vim should be evaluated in the same manner as proficiency in your mother tongue, elementary school arithmetic, etc. A lot of things in technology start with knowing your editor. Also, It is extremely customizable and you can adapt it to your way of coding and your way of doing things.
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!
Modes of Vim
Normal Mode: This is the default mode when you first open Vim. In this mode, you can navigate the file, delete text, copy text, and perform other commands.
Insert Mode: This mode allows you to insert and edit text. To enter Insert Mode from Normal Mode, press
i
.Visual Mode: In this mode, you can visually select blocks of text. To enter Visual Mode from Normal Mode, press
v
.Command-Line Mode: This mode lets you enter Vim commands. To enter Command-Line Mode from Normal Mode, press
:
.
Most of them below are in command mode
x - to delete the unwanted character
u - to undo the last command and U to undo the whole line
CTRL-R to redo
A - to append text at the end
:wq - to save and exit
:q! - to trash all changes
dw - move the cursor to the beginning of the word to delete that word
2w - to move the cursor two words forward.
3e - to move the cursor to the end of the third word forward.
0 (zero) to move to the start of the line.
d2w - which deletes 2 words .. number can be changed for deleting the number of consecutive words like d3w
dd to delete the line and 2dd to delete to line number can be changed to delete the number of consecutive words
Conclusion
Finally, when exploring the Linux command line, one will frequently come across a variety of text editors, with Vim standing out as a powerful yet complex instrument. This article aims to give newcomers all the information they need to get started with Vim, covering everything from installation to basic commands, modes, and advanced features. Vim is an indispensable text editor. Vim has a steep learning curve, but for programmers, system administrators, and anybody else who spends time at the terminal, grasping its capabilities can greatly increase productivity and efficiency. Vim is a useful tool in the Linux environment that offers a plethora of powerful text editing options with practice and exploration.
##