In the Linux world, most work is accomplished from a CLI. One of our main tasks is to manage file content. To accomplish this, we need a tool to edit files. One of the most common editors in the Linux world is the Vi editor, also known as a visual editor. Let's learn about some of the basic Vi operations before looking at my favorite commands.
What is the Vi editor?
A visual editor allows users to write and manipulate text in a file in a Unix-based operating system. An improved version of Vi is called the Vim editor. We can download Vim in Red Hat Enterprise Linux 8 (and similar distributions) by using dnf install -y vim
.
How do I use this editor?
Using this editor is quite simple. Type vi file-name
, and the editor opens. One advantage of this editor is that we can manipulate text without using a mouse. We only need the keyboard. Let's start this great tool right away.
# vi filename
This command opens up a brand new file named filename
. The file looks like this:

Here you see a ~
, which means those lines are unused. At the bottom of the page, we see the filename and [New File]. To start writing content into the file, simply press i
(insert). Now the file goes to edit mode.
Basic commands
I have written five basic commands that I use with vim
:
To copy text, use yy
and yw
:
yy
- Copies the current line.yw
- Copies the current word from the character the lowercasew
cursor is on, until the end of the word.p
- Pastes the copied text.
To move to the start or end of the file:
:1
- Moves the cursor to the start of the page.:$
- Moves the cursor to the end of the page.
To search for a particular string in the file:
/
- For example, if you want to search for the string redhat in a given file, you type:/redhat
orred*
to take you to the matching string.
To set the line numbers and paste complex texts inside the file:
set num
- Sets the line numbers.set paste
- Pastes a bulk of text from some other location.
To move forward and backward for one fullscreen:
- Ctrl+f - moves forward by fullscreen.
- Ctrl+b - moves backward by fullscreen.
Intermediate commands
I have written three advanced commands that I use with the Vim editor:
To undo and delete a particular line:
u
- Undo the previously executed command.
dd
- Deletes the current line of text.
To rename the file:
:f filename
- Helps you to rename the file.
To toggle between two open files:
:e #
- Helps you to navigate/toggle between two open files.
Conclusion
In this article, I covered the most common commands that I use in my day-to-day work with the Vim editor. By no means does this include all the available commands. Feel free to check the man page for other helpful commands as per your scenario.
[ Free online course: Red Hat Enterprise Linux technical overview. ]
About the author
I work as a Solutions Engineer at Red Hat and my day-to-day work involves OpenShift and Ansible. I'm highly passionate about open source software, cloud, security, and networking technologies.
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Customer support
- Developer resources
- Find a partner
- Red Hat Ecosystem Catalog
- Red Hat value calculator
- Documentation
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit