---
title: 'Vim text editor | Zomro'
description: 'This article will discuss the vim text editor, an application with which you can edit text files directly on the server'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/another/2022/05/01/1653558097_screenshot_14.png'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * Vim text editor 



# Vim text editor

31-05-2022

Often there is a need to edit text files directly on a server with a Linux operating system. When installing Linux OS from our templates, the _vi/vim_ text editor is already available in the system, which you can use to edit text files directly on the server.  
  
If for some reason it is not installed, then it can be installed by running the install command. For _rpm-based distributions_ :
    
    
    yum install vim

  
For _deb-based_ , the command is:
    
    
    apt-get install vim

  
In fact, _vi_ and _vim_ commands can run the same application with different settings. In earlier versions of Linux, the _vim_ editor may not be installed, but there is always a _vi_ editor.  
  
To work with the program, you need to log in to the server using the _SSH_ protocol. For example, on Windows, by installing the _PuTTY_ program, and on Linux or Mac, use the built-in _ssh_ program. Depending on the Linux system and the program you are using to connect to the server, you can copy and paste from your operating system's clipboard. For example, you can paste text into _PuTTY_ using the **SHIFT+INS** combination, and copy it by simply selecting the text. Unfortunately, this does not work on all Linux distributions on the server.  
  
In order to start the editor, log in to the server via _SSH_ using any available client - built into your OS or, for example, _PuTTY_ and run the commands:
    
    
    vi
    vim

  
For existing ones, you can specify both absolute and relative paths (an example with an absolute path is shown):
    
    
    vi /path/to/file
    vim /path/to/file

  
The _vi/vim_ editor is more complex and advanced than, for example, _nano_. Its main feature is that it has two main modes: _command mode_ and _insert mode_. In _command mode_ , almost every letter or combination performs a command. In _insert mode_ , the text is actually entered. Work in _command mode_ is performed only with the Latin keyboard layout. In order to enter the _insert mode_ , you need to press the Latin letter **'i'** or the **INSERT** button in _command mode_ (if you are already in _insert mode_ , the letter 'i' will simply appear under the cursor). Press **ESC** to exit _insert mode_.  
  
Consider the appearance of the main window of the _vim_ editor.

![Vim text editor - 1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/another/2022/05/01/1653558097_screenshot_14.png)

_Image 1. Appearance of the vim editor in command mode_

![Vim text editor - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/another/2022/05/01/1653558766_1653558757308.png)

_Image 2. Appearance of the vim editor in insert mode_

  
The program has a "clean", ascetic interface, but its capabilities are very large. The program was developed for convenient and fast control exclusively from the keyboard. Therefore, when opening a file, we see only the editing area and at the bottom a narrow status bar that shows the mode (command, insert or visual selection), additional information about the entered commands that appears during the introduction of combined commands, the line number and character in the line. All elements are customizable.  
  
Text navigation is also done differently than nano and other classic editors.  
  
In _command mode_ , you can navigate through the text using both the arrows, the **HOME** , **END** , **PG UP** , **PG DOWN** buttons, and the letters on the keyboard (the most important commands will be at the end of this section):  
**H** \- left  
**J** \- down  
**K** \- up  
**L** \- right  
You can move through the words using the **W** and **B** buttons.  
This is done in order to keep your eyes on the screen and your hands on the keyboard during editing, which greatly increases the speed of work. Most _vim_ commands are executed by pressing letters on keyboard in _command mode_.  
  
In _insert mode_ , you can use the arrows, but this does not work in all systems and terminals.  
  
The _vim_ editor also allows you to perform basic editing actions, such as copying, pasting text, searching, replacing. These buttons must be pressed in _command mode_. The following commands are written as a cheat sheet:  
**V** \- highlight text  
**Y** \- copy  
**D** \- delete selection  
**DD** (successively press the D button twice in a row) - delete a line  
**DAW** (successively press 3 letters on the keyboard) - delete a word  
**X** or **DEL** \- delete the character under the cursor  
**SHIFT+P** \- paste before cursor  
**O** \- add a line after the current one and switch to edit mode  
**SHIFT+O** \- add a line before the current one and switch to edit mode  
**U** \- undo action  
**CTRL+R** \- repeat action  
**/** (slash) - search by word  
**N** \- when searching, go to the next found  
**SHIFT+N** \- when searching, go to the previous found  
  
As mentioned above, to enter the _insert_ _mode_ , you need to use the **I** or **INSERT** button. In this case, the input will begin before the character on which the cursor was located. To enter _insert mode_ and add characters after the cursor, press the A button. Also, to enter _insert mode_ at the beginning of a line, press **SHIFT+I** , at the end of a line, press **SHIFT+A**.  
  
Separately, it is worth describing the search and replace process. The _vim_ editor uses regular expressions for this. Getting to know them is a separate topic that goes beyond the scope of this article. In general, if you switch to _search mode_ (button **'/'** in command mode) and enter a word you want to find and hit **ENTER** , the program will find it. Next, press the **N** or **SHIFT+N** to continue searching.  
  
In order to replace one word with another in the entire file in the _vim_ editor, you need to switch to a special submode of _command mode_ \- _commands mode_ \- and enter a special command. To switch to _commands mode_ , enter the character **':'**(colon) while in _command mode_. Enter all characters:
    
    
    :%s/old/new/g

where _old_ is the old word to be replaced; _new_ \- new to replace with. At the end, press the **ENTER** key.  
  
For example, I will replace the word _Lorem_ with _Hello:_

![Vim text editor - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/another/2022/05/01/1653996484_1653996449589.png)

_Image 3. Replacing a word in vim_

After hitting the **ENTER** button:

![Vim text editor - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/another/2022/05/01/1653996538_1653996488990.png)

_Image 4. Replacement done_

  
This way you can replace, for example, the name of the site in the dump of the mysql database. Example:
    
    
    :%s/example.com/domain.net/g

  
Now the most important question regarding the _vi/vim_ editor, namely: how to get out of it. To do this, switch to _commands mode_ (by pressing **':'** in _command mode_) and type one of the following sequences:  
**:q** \- exit if no changes were made  
**:q!** \- if changes have been made but you do not want to save them  
**:w** \- write (save) file  
**:wq** \- write file and exit  
  
If there are difficulties working with the _vim_ editor, then in order to leave the editor and start all over again, press the **ESC** key several times to reset all intermediate modes and to exit the _insert mode_ and type on the keyboard **:q!** . If necessary, several times.

## Conclusion

The _vim_ editor is well suited for those who want to learn and learn a lot. In experienced hands, it can greatly increase your productivity in writing text and code. Once you've spent some time getting to grips with it, you won't want to use any other editor on a Linux server.

Similar articles:

[How to connect custom ISO image to dedicated server](https://zomro.com/blog/faq/234-kak-podkljuchit-svoj-obraz-iso-k-vydelennomu-serveru) [Connecting to a Server via SSH](https://zomro.com/blog/faq/142-podkljuchenie-k-serveru-po-ssh) [How to create a telegram bot for monitoring Mikrotik located behind a NAT](https://zomro.com/blog/faq/323-how-to-create-a-telegram-bot-for-monitoring-mikrotik-located-behind-a-nat) [List of important commands for working with Docker-compose](https://zomro.com/blog/faq/304-spisok-vazhnyh-komand-dlja-raboty-s-docker-compose) [How to Install Python 3.10 on Ubuntu 20.04](https://zomro.com/blog/faq/299-kak-ustanovit-python-310-na-ubuntu-2004)

[ Dedicated servers from €88.80/mon ](/dedicated-servers)
