Text editors are an essential tool for every Linux system administrator, and RHEL 8 ships with access to both vim and nano through its default repositories. vim is a powerful modal editor favored for its speed and extensibility once the learning curve is overcome, while nano offers a straightforward, menu-driven experience suitable for quick edits. This tutorial covers installing both editors, understanding vim‘s core modes and commands, customizing vim with a ~/.vimrc file, and using nano‘s most important shortcuts. You will also learn how to set your preferred editor system-wide.
Prerequisites
- A RHEL 8 system with sudo or root access
- An active subscription or EPEL repository (standard packages are in BaseOS/AppStream)
- Basic terminal familiarity
Step 1 — Installing vim and nano
Both vim and nano are available in the default RHEL 8 repositories. Install them with a single dnf command.
# Install both editors
dnf install -y vim nano
# Verify the installed versions
vim --version | head -1
nano --version | head -1
RHEL 8 installs the full vim-enhanced package (pulled in as a dependency of the vim meta-package), which includes syntax highlighting and scripting support.
Step 2 — Understanding vim Modes and Opening Files
vim is a modal editor with three primary modes: Normal (navigation and commands), Insert (text entry), and Visual (selection). You always start in Normal mode.
# Open a file with vim
vim /etc/hosts
# Enter Insert mode (start typing text)
# Press: i
# Return to Normal mode from any mode
# Press: Esc
# Enter Visual mode (select text by character)
# Press: v
# Enter Visual Line mode (select whole lines)
# Press: V
Pressing Esc always returns you to Normal mode — use it freely whenever you are unsure of your current state.
Step 3 — Essential vim Commands
The following commands are entered in Normal mode and cover the most frequent editing operations.
# Save and quit
:wq
# Quit without saving (force)
:q!
# Save without quitting
:w
# Delete the current line
dd
# Yank (copy) the current line
yy
# Paste after the cursor
p
# Search forward for a pattern
/search_term
# Press n to jump to the next match, N for previous
# Search and replace all occurrences in the file
:%s/old_text/new_text/g
# Search and replace with confirmation prompt
:%s/old_text/new_text/gc
# Go to a specific line number (e.g., line 42)
:42
Step 4 — Configuring vim with ~/.vimrc
Persistent vim settings are stored in ~/.vimrc. Create or edit this file to enable syntax highlighting, line numbers, and sensible indentation defaults.
# Create or open the vimrc file
vim ~/.vimrc
# Recommended ~/.vimrc contents:
syntax on
set number
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set hlsearch
set incsearch
set wrap
set ruler
After saving, reopen any file with vim and the settings take effect immediately. syntax on enables color-coded highlighting for recognized file types, and set number shows line numbers in the gutter.
Step 5 — Using nano: Essential Shortcuts
nano displays its shortcut bar at the bottom of the screen at all times, making it accessible without memorization. The ^ symbol represents the Ctrl key.
# Open a file with nano
nano /etc/hosts
# Save (Write Out) the current file
# Press: Ctrl+O then Enter to confirm the filename
# Exit nano
# Press: Ctrl+X (prompts to save if there are unsaved changes)
# Search for text
# Press: Ctrl+W then type the search term and press Enter
# Go to a specific line number
# Press: Ctrl+_ then type the line number
# Cut the current line
# Press: Ctrl+K
# Paste the cut line
# Press: Ctrl+U
Step 6 — Setting the Default Editor
Many programs (such as crontab -e and git commit) open an editor determined by the EDITOR or VISUAL environment variables. Set these in your shell profile to make your preference permanent.
# Set vim as the default editor for the current session
export EDITOR=vim
export VISUAL=vim
# Make it permanent for the current user
echo 'export EDITOR=vim' >> ~/.bashrc
echo 'export VISUAL=vim' >> ~/.bashrc
source ~/.bashrc
# Alternatively, set nano as the default
echo 'export EDITOR=nano' >> ~/.bashrc
source ~/.bashrc
# Verify the setting
echo $EDITOR
Conclusion
You now have both vim and nano installed and configured on your RHEL 8 system. With a working ~/.vimrc and an understanding of vim‘s modal workflow, you can efficiently edit configuration files and scripts. nano remains a reliable fallback for quick, low-friction edits. Configuring the EDITOR environment variable ensures the correct editor is invoked across all command-line tools.
Next steps: How to Use journalctl for Systemd Log Analysis on RHEL 8, How to Manage System Packages with dnf on RHEL 8, and How to Perform a System Security Audit with auditd on RHEL 8.