DEV Community

Ilyas Anwar
Ilyas Anwar

Posted on • Updated on

View, Create, Edit file with Vim

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
Enter fullscreen mode Exit fullscreen mode

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

vim filename
Enter fullscreen mode Exit fullscreen mode

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

sudo vim filename
Enter fullscreen mode Exit fullscreen mode

You also can make new file using command

vim filename.txt
Enter fullscreen mode Exit fullscreen mode

Image description

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

Image description

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

Image description

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

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

Top comments (0)