If you are a developer this article going to be very useful for you. So basically vim or vi is a very powerful and popular text editor. Vim is a clone of vi editor and written by Bram Moolenaar. It supports all major platforms like Windows, Linux, and mac.
Vim is designed for use both from a command-line interface and as a standalone application in a graphical user interface. Vim is an improved version of vi editors.
Vim or vi have two modes one is for command and another is text mode nowadays we have a visual mode. So here will work on the command line interface.
In this article, we are going to talk about vim as well as vi editors. Here we are using a command-centric approach so in the initial phase, you can be in trouble because you need to memorise these commands but when you are perfect in this then you can faster.
- Vim or vi (Linux-based systems have vi editors but for vim, we need to download vim editor).
- Vim cheat sheet
Notes – Inside the window we need to set an environment variable to access vim using the command line.
To start we need to open the command line. If we want to create a new file then we will use the –
vim test.sh # test.sh is the file name
Now vim or vi editor will open like this image –
and if you want to open a file then the same command will work.
Vim or vi modes
Vim or vi modes are the main power of vim. So we have several modes those modes enhance the power of vim. These are –
1. Insert Mode
Using this mode we can insert text inside our file. The shortcut is i (insert text where the cursor is), o (insert text beginning of line), a ( insert text end of the line) key for insert mode.
2. Visual Mode
Using this we can use a mouse inside the command line. Like we want to select a lot of lines at once so this is very useful at that time. The shortcut is v key for visual mode.
3. Command Mode
Using this we can use commands inside our file. But we need to be careful if we are using this because at the start of the command we need to use the : symbol. The shortcut is esc key for visual mode.
Basic follow of vim or vi editors
To use vim or vi editors we have to follow these steps –
- Open or create file using vim filename command.
- Go to insert mode using i key and write code, text whatever you want.
- Now come again into command mode using ese key
- Save file using :w inside command mode.
- Exit from editor using :q inside command mode.
Basic vim or vi command
|save and exit||:wq|
|force||! (ex :w! :q!)|
|copy a line||yy|
|cut a line||dd|
|vertical split||open the specified document and split the screen so you can see multiple documents.|
You can follow this link to complete vim cheat sheet. Read more about linux.