Every Linux administrator needs at least one terminal text editor in their toolkit. When a remote server is accessible only via SSH with no GUI, when a configuration file needs editing before a service can start, or when you are recovering a broken system from a rescue shell, your text editor is your primary interface. RHEL 9 ships with both vi (the classic editor included in every Unix-like OS) and nano (a beginner-friendly editor with on-screen key guides). Installing the full-featured vim (Vi IMproved) gives you syntax highlighting, split windows, macro recording, and hundreds of plugins. This guide covers installing both editors, essential vim workflows including normal/insert/command modes, practical .vimrc configuration, and nano usage for quick edits.

Prerequisites

  • RHEL 9 server with root or sudo access

Step 1 — Install vim and nano

# Install vim (enhanced vi)
dnf install -y vim

# Install nano
dnf install -y nano

# Verify
vim --version | head -1
nano --version

RHEL 9 ships vi as part of vim-minimal. The full vim package adds syntax highlighting, the vimtutor interactive tutorial, and the spell checker.

Step 2 — Understanding vim Modes

vim operates in modes — this is the biggest conceptual difference from other editors. Understanding modes is the key to working efficiently in vim:

  • Normal mode (default) — for navigation and commands. Keys are not inserted as text. Press Esc to return here from any other mode.
  • Insert mode — for typing text. Enter with i (before cursor), a (after cursor), o (new line below), O (new line above), I (start of line), A (end of line).
  • Visual mode — for selecting text. Enter with v (character), V (line), Ctrl+v (block/column).
  • Command mode — for file operations and search/replace. Enter with : from Normal mode.

Step 3 — Essential vim Navigation

# Movement in Normal mode
h j k l         # left, down, up, right (use arrow keys too)
w / b           # next / previous word
e               # end of current word
0 / ^           # start of line / first non-blank character
$               # end of line
gg / G          # first line / last line
:50             # go to line 50
Ctrl+d / Ctrl+u # scroll down / up half a page
Ctrl+f / Ctrl+b # scroll down / up full page
%               # jump to matching bracket/parenthesis

Step 4 — Editing Commands in vim

# In Normal mode:
x               # delete character under cursor
dd              # delete (cut) current line
3dd             # delete 3 lines
yy              # yank (copy) current line
3yy             # yank 3 lines
p / P           # paste after / before cursor
u               # undo
Ctrl+r          # redo
.               # repeat last change
r               # replace single character
cw              # change word (delete word and enter insert mode)
cc              # change entire line
C               # change from cursor to end of line
D               # delete from cursor to end of line

Step 5 — Search and Replace in vim

# In Normal mode:
/pattern        # search forward for 'pattern'
?pattern        # search backward
n / N           # next / previous match
*               # search for word under cursor

# In Command mode (:):
:%s/old/new/g      # replace all occurrences in file
:%s/old/new/gc     # replace with confirmation for each
:5,20s/old/new/g   # replace only in lines 5 to 20
:/pattern/d        # delete lines matching pattern

Step 6 — File Operations in vim

# In Command mode (:):
:w              # save file
:w filename     # save to a different file
:q              # quit (fails if unsaved changes)
:q!             # quit without saving (discard changes)
:wq             # save and quit
:x              # save and quit (same as :wq if file was changed)
ZZ              # save and quit (Normal mode shortcut)
ZQ              # quit without saving (Normal mode shortcut)
:e!             # reload file from disk, discard changes
:set number     # show line numbers
:set nonumber   # hide line numbers
:set paste      # enable paste mode (disables auto-indent for pasting)

Step 7 — Configure vim with .vimrc

vi ~/.vimrc
" ~/.vimrc — personal vim configuration

" Show line numbers
set number

" Enable syntax highlighting
syntax on

" Use 4 spaces for indentation
set tabstop=4
set shiftwidth=4
set expandtab

" Smart indentation
set autoindent
set smartindent

" Highlight search results
set hlsearch

" Search as you type
set incsearch

" Case-insensitive search (override with C for case-sensitive)
set ignorecase
set smartcase

" Show matching brackets
set showmatch

" Status bar
set ruler
set showcmd

" No swap files
set noswapfile

" Visual bell instead of audible bell
set visualbell

" Set 256 colours in terminal
set t_Co=256

" Set background for dark terminals
set background=dark

Step 8 — System-Wide vim Configuration

vi /etc/vimrc.local
" System-wide settings applied to all users
syntax on
set number
set tabstop=4
set expandtab
set hlsearch

Step 9 — Using nano

nano is significantly simpler than vim — it is modal-free and displays keyboard shortcuts at the bottom of the screen:

# Open or create a file
nano /etc/nginx/nginx.conf

# Open at a specific line number
nano +50 /etc/nginx/nginx.conf

Key shortcuts in nano (^ means Ctrl, M- means Alt):

  • Ctrl+O — write (save) the file
  • Ctrl+X — exit (prompts to save if modified)
  • Ctrl+K — cut current line
  • Ctrl+U — paste cut text
  • Ctrl+W — search (Where Is)
  • Ctrl+ — search and replace
  • Ctrl+G — open help
  • Ctrl+_ — go to a specific line and column
  • Alt+U — undo
  • Alt+E — redo

Step 10 — Configure nano with .nanorc

vi ~/.nanorc
# Enable syntax highlighting
include "/usr/share/nano/*.nanorc"

# Show line numbers
set linenumbers

# Enable auto-indentation
set autoindent

# Enable smooth scrolling
set smooth

# Tab size
set tabsize 4

# Convert tabs to spaces
set tabstospaces

Choosing Between vim and nano

  • Use nano for quick config file edits, when you are under time pressure, or when introducing others to terminal editing.
  • Use vim for sustained editing work, programming, multi-file editing, macros, or when you need regex search/replace, split windows, or plugins.

Conclusion

You now have both vim and nano installed and configured on RHEL 9. The core vim skill — understanding Normal, Insert, and Command modes — unlocks a highly efficient editing workflow once it becomes muscle memory. For immediate productivity, nano’s on-screen shortcuts get you editing any configuration file in seconds. Setting up ~/.vimrc with line numbers, syntax highlighting, and consistent indentation makes vim suitable for editing infrastructure files, shell scripts, and configuration daily.

Next steps: How to Perform a System Security Audit with auditd on RHEL 9, How to Manage System Packages with dnf on RHEL 9, and How to Use tmux for Terminal Multiplexing on RHEL 9.