How to Install and Configure vim and nano on RHEL 7

Every Linux system administrator spends a significant portion of their time editing configuration files, scripts, and documentation directly on the server. RHEL 7 includes the minimal vi editor by default, but the full-featured vim and the beginner-friendly nano are far more practical for daily use. This guide covers installing both editors, understanding vim’s modal editing model, customizing your environment with .vimrc and .nanorc, and building the command muscle-memory needed to edit files confidently on any RHEL 7 system.

Prerequisites

  • A RHEL 7 system with a registered subscription or access to a configured yum repository
  • Root or sudo privileges
  • Basic familiarity with the Linux terminal

Step 1: Installing vim on RHEL 7

RHEL 7 ships with a stripped-down vi provided by the vim-minimal package. For the full vim experience — including syntax highlighting, plugin support, and extended commands — you need vim-enhanced:

# Check what is currently installed
rpm -q vim-minimal vim-enhanced

# Install the full vim
sudo yum install -y vim-enhanced

# Verify the installation
vim --version | head -5

After installation, vim is available as both vim and vi (the system’s /usr/bin/vi alternative is updated automatically). You can also install useful companion packages:

# Vim documentation (offline :help)
sudo yum install -y vim-common

# Graphical vim (if you have a desktop environment)
sudo yum install -y gvim

Step 2: Understanding vim’s Three Core Modes

The most important concept in vim is that it is a modal editor — the meaning of every keystroke depends on which mode you are currently in. New users are often confused because typing text in the wrong mode triggers commands instead of inserting characters.

Normal Mode (Command Mode)

This is the default mode when you open a file. In Normal mode, every key is a command. You cannot type text into the document from this mode. Press Esc at any time to return to Normal mode.

Insert Mode

In Insert mode, keys type characters into the document as expected. Enter Insert mode from Normal mode by pressing:

  • i — insert before the cursor
  • a — append after the cursor
  • o — open a new line below and enter Insert mode
  • O — open a new line above and enter Insert mode
  • I — insert at the beginning of the line
  • A — append at the end of the line

Visual Mode

Visual mode lets you select blocks of text for copying, deleting, or replacing. Enter it from Normal mode with:

  • v — character-wise visual selection
  • V — line-wise visual selection
  • Ctrl+v — block/column visual selection

Step 3: Essential vim Commands

The following commands are used constantly when working with configuration files on RHEL 7. All are entered from Normal mode unless noted.

Saving and Quitting

# Save the file (write)
:w

# Save and quit
:wq

# Quit without saving (discard changes)
:q!

# Save as a different filename
:w /tmp/myfile_backup.conf

# Save and quit (shorthand)
ZZ

Navigation

# Move by character
h  (left)   j  (down)   k  (up)   l  (right)

# Jump to beginning / end of line
0      $

# Jump to first / last line of file
gg     G

# Jump to line number 42
:42

# Move forward / backward one word
w      b

# Page down / page up
Ctrl+f    Ctrl+b

Editing

# Delete (cut) the current line
dd

# Delete 5 lines
5dd

# Copy (yank) the current line
yy

# Copy 3 lines
3yy

# Paste after cursor
p

# Paste before cursor
P

# Undo last change
u

# Redo (undo the undo)
Ctrl+r

# Delete from cursor to end of line
D

# Delete current character
x

Searching and Replacing

# Search forward for a pattern
/searchterm

# Search backward
?searchterm

# Jump to next / previous match
n     N

# Replace first occurrence on current line
:s/old/new/

# Replace all occurrences on current line
:s/old/new/g

# Replace all occurrences in entire file
:%s/old/new/g

# Replace with confirmation
:%s/old/new/gc

Step 4: Configuring vim with .vimrc

The ~/.vimrc file is loaded every time you start vim. A well-configured .vimrc makes vim much more comfortable for editing RHEL 7 configuration files and shell scripts:

vim ~/.vimrc

Add the following configuration:

" Enable syntax highlighting
syntax on

" Show line numbers
set number

" Highlight the current line
set cursorline

" Show matching brackets
set showmatch

" Enable incremental search (highlight as you type)
set incsearch

" Highlight search results
set hlsearch

" Case-insensitive search (smart: case-sensitive if uppercase used)
set ignorecase
set smartcase

" Use 4 spaces for indentation (common for shell scripts)
set tabstop=4
set shiftwidth=4
set expandtab

" Auto-indent new lines
set autoindent

" Show command being typed in the status bar
set showcmd

" Enable file type detection and plugins
filetype plugin indent on

" Show file info in status line
set laststatus=2

" Allow backspace over everything in insert mode
set backspace=indent,eol,start

" Disable backup files (optional, reduces clutter)
set nobackup
set noswapfile

Save and reload: changes take effect the next time you open vim, or immediately in a running session with :source ~/.vimrc.

Step 5: Installing nano on RHEL 7

The nano editor is modeless — you type text directly without switching modes — making it ideal for quick edits or users new to terminal editors. Check if it is installed and install it if needed:

# Check if nano is installed
rpm -q nano

# Install nano
sudo yum install -y nano

# Verify
nano --version

Step 6: Basic nano Usage and Shortcuts

Open a file with nano by passing the filename as an argument:

nano /etc/hosts
nano /etc/sysconfig/network-scripts/ifcfg-eth0

The bottom two lines of the screen always display the most important shortcuts. The caret symbol (^) means Ctrl:

  • Ctrl+O — Write (save) the file
  • Ctrl+X — Exit nano (prompts to save if there are unsaved changes)
  • Ctrl+G — Display the help screen
  • Ctrl+W — Search (Where Is)
  • Ctrl+ — Search and replace
  • Ctrl+K — Cut the current line
  • Ctrl+U — Paste the cut line
  • Ctrl+6 — Mark text for selection (then move cursor to extend selection)
  • Alt+6 — Copy the selected text or current line
  • Ctrl+C — Display cursor position (line and column)
  • Ctrl+_ — Go to a specific line number
  • Alt+U — Undo
  • Alt+E — Redo

Step 7: Configuring nano with .nanorc

nano reads its per-user configuration from ~/.nanorc. Create or edit this file to improve the editing experience:

nano ~/.nanorc

Recommended settings:

# Enable syntax highlighting for common file types
include "/usr/share/nano/*.nanorc"

# Show line numbers in the gutter
set linenumbers

# Enable smooth scrolling (one line at a time instead of half-page)
set smooth

# Auto-indent new lines
set autoindent

# Use spaces instead of tab characters
set tabsize 4
set tabstospaces

# Enable mouse support (if your terminal supports it)
set mouse

# Show cursor position in the status bar
set constantshow

# Enable soft text wrapping (display only, does not insert line breaks)
set softwrap

# Disable the "New File" message when opening a non-existent file
set nonewlines

Changes to ~/.nanorc take effect the next time you open nano.

Step 8: Choosing Between vim and nano

Both editors are available on virtually every RHEL 7 system. A practical approach:

  • Use nano for quick one-line edits, cron jobs, or when you need to hand off to a colleague who is not comfortable with vim.
  • Use vim for complex edits, scripting, or when you need search-and-replace across a large file.
  • Set your preferred editor as the default by adding to ~/.bashrc:
# Set vim as the default editor
export EDITOR=vim
export VISUAL=vim

Reload your shell: source ~/.bashrc

Conclusion

Installing vim-enhanced and nano on RHEL 7 takes a single yum install command for each, and a few minutes spent configuring .vimrc and .nanorc pays dividends across every future editing session. The key to becoming productive with vim is accepting that Normal mode is the starting point, not an obstacle — once navigation and editing commands become muscle memory, vim’s speed far surpasses any graphical editor for server-side work. nano, meanwhile, remains the fastest path to a quick edit for any level of user. Keep both tools in your toolbox.