View, Create, Edit file with Vim
Tags: vim
Published: 2022-09-21 09:06:58

**Editing Files with Vim**
A key design principle of Linux is that information and configuration settings are commonly stored in text-based files. These files can be structured in various ways, as lists of settings, in INI-like formats, as structured XML or YAML, and so on. However, the advantage of text files is that they can be viewed and edited using any simple text editor.

Vim is an improved version of the vi editor distributed with Linux and UNIX systems. Vim is highly configurable and efficient for practiced users, including such features as split screen editing, color formatting, and highlighting for editing text.

**Why Learn Vim?**
You should know how to use at least one text editor that can be used from a text-only shell prompt. If you do, you can edit text-based configuration files from a terminal window, or from remote logins through ssh or the Web Console. Then you do not need access to a graphical desktop in order to edit files on a server, and in fact that server might not need to run a graphical desktop environment at all.

But then, why learn Vim instead of other possible options? The key reason is that Vim is almost always installed on a server, if any text editor is present. This is because vi was specified by the POSIX standard that Linux and many other UNIX-like operating systems comply with in large part.

In addition, Vim is often used as the vi implementation on other common operating systems or distributions. For example, macOS currently includes a lightweight installation of Vim by default. So Vim skills learned for Linux might also help you get things done elsewhere.


**How To Use Vim**
First of all, you had installed vim on your terminal. In Linux, especially in RHEL you can use

```
yum -y install vim
```

After you had installed it, you can open your file with these command

```
vim filename
```
if the file required root user to access it you can use

```
sudo vim filename
```

You also can make new file using command

```
vim filename.txt
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4f92t7y7azjwzf8ze2g.jpg)

Before start editing, you must press **i** in your keyboard to insert.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ax47gavkv5ap0a9rqmqv.jpg)

You can use the arrow button to point the text that you want to edit

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrmyasm651wc9uxb7mzc.jpg)

If you want delete a text block, you can using visual block mode by press **ctrl+v**, use arrow button to select and for delete use **x** or **d**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ibtsq5jl4r9lqlix7tq.png)

> **Notes:**
> Visual Mode in Vim are there keystrokes of the visual mode:
> • Character mode: v
> • Line mode: shift+v
> • Block mode: ctrl+v

If you have finished your editing, you can save and exit by press **escape** button, write **:wq**, and click **enter**

> Note:
> **:wq** : save changes and exit
> **:q!**: exit and discard changes
> **:wq!**: to override file, save changes and exit

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hc7zu94iv1jhpr7hzfm6.jpg)