The vim
command¶
The vim is a text editor for Unix that comes with Linux, BSD, and macOS. It is known to be fast and powerful, partly because it is a small program that can run in a terminal (although it has a graphical interface). Vim text editor is developed by Bram Moolenaar. It supports most file types and the vim editor is also known as a programmer's editor. It is mainly because it can be managed entirely without menus or a mouse with a keyboard.
Note: Do not confuse vim
with vi
. vi
, which stands for "Visual", is a text editor that was developed by Bill Joy in 1976. vim
stands for "Vi Improved", and is an improved clone of the vi
editor.
The most searched question about vim
:¶
How to exit vim editor?
The most searched question about vim editor looks very funny but it's true that the new user gets stuck at the very beginning when using vim editor.
The command to save the file and exit vim editor: :wq
The command to exit vim editor without saving the file: :q!
Fun reading:¶
Here's a survey for the same question, look at this and do not think to quit the vim editor.
Installation:¶
First check if vim is already installed or not, enter the following command: vim --version
If it is already installed it will show its version, else we can run the below commands for the installations:
On Ubuntu/Debian:
sudo apt-get install vim
On CentOS/Fedora:
sudo yum install vim
If you want to use advanced features on CentOS/Fedora, you'll need to install enhanced vim editor, to do this run the following command:
sudo yum install -y vim-enhanced
Syntax:¶
vim [FILE_PATH/FILE_NAME]
Examples:¶
- To open the file named "demo.txt" from your current directory:
vim demo.txt
- To open the file in a specific directory:
vim {File_Path/filename}
- To open the file starting on a specific line in the file:
vim {File_Path/filename} +LINE_NUMBER
Modes in vim editor:¶
There are some arguments as to how many modes that vim has, but the modes you're most likely to use are command mode
and insert mode
. These modes will allow you to do just about anything you need, including creating your document, saving your document, and doing advanced editing, including taking advantage of search and replace functions.
Workflow of vim
editor:¶
- Open a new or existing file with
vim filename
. - Type
i
to switch into insert mode so that you can start editing the file. - Enter or modify the text of your file.
- When you're done, press the
Esc
key to exit insert mode and back to command mode. - Type :w or :wq to save the file or save and exit from the file respectively.
Interactive training¶
In this interactive tutorial, you will learn the different ways to use the vim
command:
Additional Flags and their Functionalities:¶
Flags/Options | |
---|---|
-e | Start in Ex mode (see Ex-mode) |
-R | Start in read-only mode |
-R | Start in read-only mode |
-g | Start the GUI |
-eg | Start the GUI in Ex mode |
-Z | Like "vim", but in restricted mode |
-d | Start in diff mode diff-mode |
-h | Give usage (help) message and exit |
+NUMBER | Open a file and place the cursor on the line number specified by NUMBER |
Read more about vim:¶
vim can not be learned in a single day, use in day-to-day tasks to get hands-on in vim editor.
To learn more about vim
follow the given article: