Hey, Everyone in our today's blog we will most important, most hated, most cool, etc code editor which is VIM. Many people don't like using Vim as a code editor but when you work with the server you have to use VIM or nano editor and today we are learning VIM because kind of like it because it makes me look cool.
What is Vim
Vim is one of the most popular text editors among Linux users. Linux System Administrators especially often prefer it to other editors. It is a free and open-source cross-platform text editor.
How to Install Vim
Vim runs across various platforms such as Windows, Linux, and Mac.
To install Vim on Windows, download the executable file from the Vim site and run the file. Follow the instructions shown on the screen and you'll be good to go.
Vim comes pre-installed on most *nix operating systems. But if it's installed on your system, you can install it with a package manager of your choice.
Here's the installation command for Debian-based operating systems:
sudo apt-get update
sudo apt-get install vim
Terminal commands to install Vim on Debian-based operating systems
To ensure that it's installed properly, run
which vim
and you should get/usr/bin/vim
in your output.
Now if everything is right you can use VIM. you can check by writing VIM on your terminal and it will show this
VIM Modes
You should be aware of the most important concept in Vim before moving on: modes in Vim.
Everything in Vim is considered a mode. You can achieve whatever you want if you understand modes in Vim. There are many modes in Vim. But, we'll be looking at the 4 most important modes.
They are:
Command Mode
Command-Line Mode
Insert Mode
Visual Mode
Let's explore them one by one.
What is Command Mode?
This is the default mode (also called Normal mode) in Vim. Whenever Vim starts, you'll be in this mode. You can switch to any mode from this mode. You can't do this in any other modes.
Basically, to switch from one mode to another, you have to come to Command Mode first and then navigate to the other mode. The commands that you run without any prefix (colon)(:) indicate that you're running the command in command mode.
What is Insert Mode?
This mode is used to edit the contents of the file. You can switch to insert mode by pressing i
from command mode. You can use the Esc
key to switch back to command mode.
What is Command Line Mode?
You can use this mode to play around with some commands. But the commands in this mode are prefixed with a colon (:). You can switch to this mode by pressing : (colon) in command mode.
What is Visual Mode?
You use this mode to visually select some text and run commands over that section of code. You can switch to this mode by pressing v
from the command mode.
The above 4 modes are enough to perform a basic set of file operations in Vim.
Ok, the theory is done. Let's explore Vim practically.
Let's VIM
For this blog, we will keep it very simple. So let start
Q create a file and write some content on that file.
To create a file I will use the vim
command to create a file. let me show you how it looks.
so here vim created a file name textfile.txt
Now it we will write some content on the file.
Now we have written some content on the file it time's to write the file or you can say that it's time to save the file to do so we have to first get into the command mode for that we will press Ese
the key the we will write :w
which will save the file
Now the file is saved we will exit from Vim and to do so we will use the command :q
to exit.
Now if you want to check that your file has been saved properly or not so to check that we will use cat
command to see inside the file.
Nice all of our content is saved.
The End
That's all for today there are many other commands you can explore so go ahead and try.