We all know how vital text editing is when managing Linux systems. The nano text editor has become more critical over the years. However, many sysadmins prefer the Vim text editor, and it is still the default on many systems.
This is the first article in a series that covers some essential Linux tools. My second article discusses: "The four things you must be able to do in nano." It is a companion article to this one.
When I taught Linux classes regularly, I found that many students were intimidated and overwhelmed by Vim's power and flexibility. I told these students to start with the basics and gain confidence by accomplishing the following four tasks:
- Create/open a file
- Edit the file
- Save changes
- Exit the file
This article is aimed at new Linux users.
Vim modes
Before we start on the specifics, I'll quickly review the Vim modes. The way I explain modes is this: Depending on the mode, the keyboard responds differently. If you're in Command mode, i issues the command to move to Insert mode. If you're in Insert mode, i enters a lowercase i character into the text.
List of modes:
- Command mode - issues commands to Vim (use Esc to get to Command mode)
- Execute mode - executes commands in Vim (use colon : to get to Execute mode)
- Insert mode - inserts text in a file (use i to get to Insert mode)
Note: There are many ways of entering Insert mode. I suggest the i character here because it's easy.
[ Readers also like: Vim: Basic and intermediate commands ]
Create or open a file
To create a new file by using Vim, type vim /path/filename
. For example, to create a new file named "distributions" in my Documents directory, I type the following:
# vim ~/Documents/distributions
The new file opens in Command mode.
I use the same process to open an existing file named "demo" in the Documents directory:
# vim ~/Documents/demo
Edit a file
Vim starts in Command mode, so I need to switch to Insert mode to add or edit content. There are many ways of switching to Insert mode. Most of them center around changing modes and positioning the cursor somewhere specific in the file. When you're just starting out, it's easier to simply remember i for Insert mode and manage the cursor position by using the arrow keys.
I'm in my distributions file, so I select i and begin to enter content:
![File with Vim's Insert mode highlighted](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-07/VimInsertMode.png.webp?itok=F_vl5l80)
Save a file
Now that I have added or modified content in my file, it's time to save my changes. I must leave Insert mode, so I press Esc to return to Command mode. I enter :w to save (write) my changes:
![File with Vim's :w command highlighted](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-07/VimW.png.webp?itok=XVX6ITew)
Exit Vim
To close the Vim text editor, I ensure that I'm in Command mode (press Esc if you aren't sure), and then select :q (quit):
![File with Vim's :q command highlighted](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-07/VimQ.png.webp?itok=uOJA-T1d)
Combine commands
Those of you with a little Vim experience realize that I could have combined the write and exit steps. To simultaneously save changes and exit Vim, enter the following :wq (write and then quit). Here's an example:
![File with Vim's :wq command highlighted](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-07/VimWQ.png.webp?itok=4fhWsDyC)
If you want to exit Vim without saving your changes to the file, you use the :q! key combination, like this:
![File with Vim's :q! command highlighted](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-07/VimQbang.png.webp?itok=mvHV6HEc)
[ Want to test your sysadmin skills? Take a skills assessment today. ]
Wrap up
There is a lot more to Vim than these simple steps. However, too many new users are intimidated and overwhelmed. Start slow with these four essential functions. If you prefer nano, then use it. At least if you connect to a system that does not have nano installed, you can accomplish some basic tasks using Vim.
Once you master these easy Vim tasks, you can investigate additional functions to become more efficient. Personally, I use Vim whenever possible on my Linux installations.
Über den Autor
Damon Garn owns Cogspinner Coaction, LLC, a technical writing, editing, and IT project company based in Colorado Springs, CO. Damon authored many CompTIA Official Instructor and Student Guides (Linux+, Cloud+, Cloud Essentials+, Server+) and developed a broad library of interactive, scored labs. He regularly contributes to Enable Sysadmin, SearchNetworking, and CompTIA article repositories. Damon has 20 years of experience as a technical trainer covering Linux, Windows Server, and security content. He is a former sysadmin for US Figure Skating. He lives in Colorado Springs with his family and is a writer, musician, and amateur genealogist.
Nach Thema durchsuchen
Automatisierung
Das Neueste zum Thema IT-Automatisierung für Technologien, Teams und Umgebungen
Künstliche Intelligenz
Erfahren Sie das Neueste von den Plattformen, die es Kunden ermöglichen, KI-Workloads beliebig auszuführen
Open Hybrid Cloud
Erfahren Sie, wie wir eine flexiblere Zukunft mit Hybrid Clouds schaffen.
Sicherheit
Erfahren Sie, wie wir Risiken in verschiedenen Umgebungen und Technologien reduzieren
Edge Computing
Erfahren Sie das Neueste von den Plattformen, die die Operations am Edge vereinfachen
Infrastruktur
Erfahren Sie das Neueste von der weltweit führenden Linux-Plattform für Unternehmen
Anwendungen
Entdecken Sie unsere Lösungen für komplexe Herausforderungen bei Anwendungen
Original Shows
Interessantes von den Experten, die die Technologien in Unternehmen mitgestalten
Produkte
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud-Services
- Alle Produkte anzeigen
Tools
- Training & Zertifizierung
- Eigenes Konto
- Kundensupport
- Für Entwickler
- Partner finden
- Red Hat Ecosystem Catalog
- Mehrwert von Red Hat berechnen
- Dokumentation
Testen, kaufen und verkaufen
Kommunizieren
Über Red Hat
Als weltweit größter Anbieter von Open-Source-Software-Lösungen für Unternehmen stellen wir Linux-, Cloud-, Container- und Kubernetes-Technologien bereit. Wir bieten robuste Lösungen, die es Unternehmen erleichtern, plattform- und umgebungsübergreifend zu arbeiten – vom Rechenzentrum bis zum Netzwerkrand.
Wählen Sie eine Sprache
Red Hat legal and privacy links
- Über Red Hat
- Jobs bei Red Hat
- Veranstaltungen
- Standorte
- Red Hat kontaktieren
- Red Hat Blog
- Diversität, Gleichberechtigung und Inklusion
- Cool Stuff Store
- Red Hat Summit