Vim is the standard terminal-based text editor on Linux and Unix systems. It is an improved version of vi, the editor that ships with every Unix-like OS. Vim adds features like syntax highlighting, split windows, plugin support, and powerful search and replace – making it suitable for everything from quick config edits to full development workflows. The official project page is at vim.org.
This guide covers Vim installation and configuration on RHEL 10, Rocky Linux 10, AlmaLinux 10, and Ubuntu 24.04. We walk through Vim modes, navigation, search and replace, .vimrc configuration, split windows, tabs, and plugin management with vim-plug. By the end you will have Vim set up as a productive editing environment with plugins for file browsing, fuzzy search, and status line enhancement.
Prerequisites
- A server or workstation running RHEL 10, Rocky Linux 10, AlmaLinux 10, or Ubuntu 24.04 LTS
- Root or sudo access
- Internet access for package installation and plugin downloads
- Basic familiarity with the Linux terminal
Step 1: Install Vim on Linux
Most minimal Linux installations ship with vi or vim-minimal, which lacks features like syntax highlighting and plugin support. Install the full Vim package to get everything.
Install Vim on RHEL 10 / Rocky Linux 10 / AlmaLinux 10
Use dnf to install the enhanced version of Vim.
sudo dnf install vim-enhanced -y
Install Vim on Ubuntu 24.04
On Ubuntu, the package is simply called vim.
sudo apt update
sudo apt install vim -y
Verify the Installation
Confirm Vim is installed and check the version.
vim --version | head -1
The output confirms Vim is installed with the major and minor version number.
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Apr 15 2025 00:00:00)
You can also set Vim as the default editor system-wide so that tools like crontab, git, and visudo use it.
sudo update-alternatives --set editor /usr/bin/vim.basic
On RHEL-based systems, set the EDITOR variable in your shell profile instead.
echo 'export EDITOR=vim' >> ~/.bashrc
source ~/.bashrc
Step 2: Understand Vim Modes
Vim operates in distinct modes, each designed for a specific type of interaction. Understanding modes is the key to using Vim efficiently – every keystroke behaves differently depending on which mode you are in.
Normal Mode
This is the default mode when you open Vim. You navigate the file, delete text, copy and paste, and issue commands from here. Press Esc from any other mode to return to Normal mode.
Insert Mode
Press i to enter Insert mode. Now keystrokes insert text at the cursor position, just like a regular text editor. Other ways to enter Insert mode include a (append after cursor), o (open new line below), and O (open new line above).
Visual Mode
Press v to enter Visual mode for character-wise selection, V for line-wise selection, or Ctrl+v for block (column) selection. Selected text can then be copied, deleted, or manipulated with Normal mode commands.
Command-Line Mode
Press : from Normal mode to enter Command-line mode. This is where you run commands like :w (write/save), :q (quit), :wq (save and quit), and :q! (quit without saving). You also run search and replace, set options, and execute shell commands from here.
Step 3: Basic Navigation and Editing
Vim navigation works from Normal mode. The core movement keys are h (left), j (down), k (up), and l (right). Arrow keys also work, but the h/j/k/l keys keep your fingers on the home row and are faster once you build the muscle memory.
Word and Line Navigation
Move by words and lines for faster navigation across files.
w– jump to the start of the next wordb– jump to the start of the previous worde– jump to the end of the current word0– jump to the beginning of the line$– jump to the end of the linegg– jump to the first line of the fileG– jump to the last line of the file:42– jump to line 42
Editing Commands
These commands work in Normal mode and are the foundation of efficient text editing in Vim.
x– delete the character under the cursordd– delete (cut) the entire current lineyy– yank (copy) the entire current linep– paste after the cursoru– undo the last changeCtrl+r– redodw– delete from cursor to end of wordcw– change word (delete word and enter Insert mode)ciw– change inner word (replace entire word regardless of cursor position)
Step 4: Search and Replace in Vim
Vim has a powerful regex-based search and replace engine. For system administrators editing configuration files, this is one of the most valuable features.
Search
Press / followed by a pattern to search forward, or ? to search backward. Press n to jump to the next match and N for the previous match.
/listen_address
This searches for the string “listen_address” in the file. Vim highlights all matches and jumps to the first one.
Search and Replace
The substitute command replaces text across the file. The basic syntax is :%s/old/new/g where % means the entire file and g means all occurrences on each line.
:%s/127\.0\.0\.1/0.0.0.0/g
This replaces every occurrence of 127.0.0.1 with 0.0.0.0 in the file. Add the c flag to confirm each replacement.
:%s/localhost/db.example.com/gc
Vim prompts you at each match with options to replace (y), skip (n), replace all remaining (a), or quit (q).
Search and Replace in a Range
You can limit the replacement to specific lines. This example replaces only on lines 10 through 25.
:10,25s/old_value/new_value/g
Step 5: Configure Vim with .vimrc
The ~/.vimrc file controls Vim’s behavior and appearance. Every setting you want to persist between sessions goes here. Create or edit the file to customize your environment.
vim ~/.vimrc
Add the following configuration for a practical editing environment with line numbers, syntax highlighting, proper tab handling, and mouse support.
" --- General Settings ---
set nocompatible " Disable vi compatibility mode
set encoding=utf-8 " Use UTF-8 encoding
set fileencoding=utf-8 " Save files as UTF-8
" --- Display ---
set number " Show line numbers
set relativenumber " Show relative line numbers
set cursorline " Highlight the current line
set showmatch " Highlight matching brackets
set laststatus=2 " Always show the status line
set ruler " Show cursor position in status line
syntax on " Enable syntax highlighting
set background=dark " Optimize colors for dark terminals
" --- Tabs and Indentation ---
set tabstop=4 " Display tabs as 4 spaces wide
set shiftwidth=4 " Indent by 4 spaces
set expandtab " Convert tabs to spaces
set autoindent " Copy indent from current line on new line
set smartindent " Auto-indent after braces and keywords
" --- Search ---
set hlsearch " Highlight search results
set incsearch " Search as you type
set ignorecase " Case-insensitive search
set smartcase " Case-sensitive if uppercase used
" --- Mouse and Clipboard ---
set mouse=a " Enable mouse in all modes
set clipboard=unnamedplus " Use system clipboard
" --- Performance ---
set ttyfast " Faster terminal redrawing
set lazyredraw " Don't redraw during macros
" --- File Handling ---
set nobackup " Don't create backup files
set noswapfile " Don't create swap files
set autoread " Reload files changed outside Vim
" --- Wildmenu (command-line completion) ---
set wildmenu " Visual autocomplete for commands
set wildmode=list:longest " Complete to longest common string
Save and close the file. The settings take effect the next time you open Vim, or you can reload without restarting.
:source ~/.vimrc
Step 6: Work with Split Windows and Tabs
Vim supports split windows and tabs for working with multiple files simultaneously. This is especially useful when editing related configuration files or comparing two files side by side.
Split Windows
Open a horizontal split with :split (or :sp) and a vertical split with :vsplit (or :vs).
:split /etc/hosts
:vsplit /etc/hostname
Navigate between splits using Ctrl+w followed by a direction key.
Ctrl+w h– move to the left splitCtrl+w j– move to the split belowCtrl+w k– move to the split aboveCtrl+w l– move to the right splitCtrl+w =– equalize split sizes:close– close the current split
Tabs
Tabs let you organize multiple files into separate views. Open a file in a new tab with :tabnew.
:tabnew /etc/nginx/nginx.conf
Navigate between tabs with these commands.
gt– go to next tabgT– go to previous tab:tabclose– close current tab:tabonly– close all tabs except current
Step 7: Install Plugins with vim-plug
vim-plug is a lightweight plugin manager for Vim. It handles downloading, updating, and loading plugins with minimal configuration.
Install vim-plug by downloading the script to Vim’s autoload directory. Make sure curl and git are installed first.
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Now add a plugin section to ~/.vimrc. Open the file and add the following block at the top, before your other settings.
vim ~/.vimrc
Add this plugin block at the beginning of the file.
call plug#begin('~/.vim/plugged')
" File browser
Plug 'preservim/nerdtree'
" Fuzzy file finder
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" Status line
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Git integration
Plug 'tpope/vim-fugitive'
" Syntax checking
Plug 'dense-analysis/ale'
" Auto-pairs for brackets
Plug 'jiangmiao/auto-pairs'
call plug#end()
Save the file, then open Vim and run the install command.
vim +PlugInstall +qall
vim-plug downloads each plugin from GitHub into ~/.vim/plugged/. To update plugins later, run :PlugUpdate inside Vim. To remove a plugin, delete its Plug line from .vimrc and run :PlugClean.
Step 8: Useful Vim Plugins
The plugins we installed in the previous step add practical functionality. Here is how to use the key ones.
NERDTree – File Browser
NERDTree adds a sidebar file explorer to Vim. Toggle it open with the following command in Normal mode.
:NERDTreeToggle
For quicker access, add a keyboard shortcut to ~/.vimrc.
" Toggle NERDTree with Ctrl+n
nnoremap <C-n> :NERDTreeToggle<CR>
" Close Vim if NERDTree is the only window left
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
Inside NERDTree, use o to open a file, t to open in a new tab, s for a vertical split, and i for a horizontal split.
fzf.vim – Fuzzy File Finder
fzf lets you search for files, buffers, and content at high speed. The :Files command opens a fuzzy search across the current directory. The :Rg command (requires ripgrep) searches file contents.
Install ripgrep on the system for content search to work. If you manage Linux servers regularly, tools like Vim on FreeBSD follow a similar setup process.
sudo dnf install ripgrep -y # RHEL/Rocky/Alma
sudo apt install ripgrep -y # Ubuntu/Debian
Add keybindings for fzf in ~/.vimrc.
" Fuzzy search files with Ctrl+p
nnoremap <C-p> :Files<CR>
" Search file contents with leader+f
nnoremap <leader>f :Rg<CR>
" Search open buffers
nnoremap <leader>b :Buffers<CR>
vim-airline – Status Line
vim-airline replaces the default status line with a rich, informative bar showing the current mode, file encoding, git branch (if vim-fugitive is installed), line/column position, and file type. It works out of the box with no configuration needed. To change the theme, add this to ~/.vimrc.
let g:airline_theme='dark'
Step 9: Use Vim as an IDE with LSP and Autocomplete
Vim can function as a lightweight IDE with Language Server Protocol (LSP) support. LSP provides real-time diagnostics, code completion, go-to-definition, and rename refactoring for languages like Python, Go, Bash, and YAML.
Install LSP Client Plugin
Add these plugins to the vim-plug section of ~/.vimrc.
" LSP support
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
" Autocomplete
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Run :PlugInstall inside Vim to install them. The vim-lsp-settings plugin automatically detects the file type and offers to install the appropriate language server when you open a file.
Install a Language Server
Open a Python file in Vim, and the plugin prompts you to install pylsp (Python Language Server). Accept the prompt, and Vim downloads and configures the server automatically.
For other languages, open a file of that type and vim-lsp-settings handles the rest. Supported languages include Go (gopls), Bash (bash-language-server), YAML (yaml-language-server), and many others.
LSP Keybindings
Add these keybindings to ~/.vimrc for fast access to LSP features.
" LSP keybindings
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> K <plug>(lsp-hover)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
endfunction
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
With this configuration, press gd to go to definition, gr to find references, K to show documentation, and leader+rn to rename a symbol. The autocomplete plugin provides suggestions as you type, triggered by Ctrl+n or automatically if supported by the language server. If you use terminal sharing tools like GoTTY, the LSP features work through the browser session as well.
Essential Vim Commands Reference
This table summarizes the most commonly used Vim commands for quick reference.
| Command | Description |
|---|---|
i | Enter Insert mode at cursor |
Esc | Return to Normal mode |
:w | Save the file |
:q | Quit Vim |
:wq | Save and quit |
:q! | Quit without saving |
dd | Delete current line |
yy | Yank (copy) current line |
p | Paste after cursor |
u | Undo |
Ctrl+r | Redo |
/pattern | Search forward for pattern |
n / N | Next / previous search match |
:%s/old/new/g | Replace all occurrences in file |
:split file | Open horizontal split |
:vsplit file | Open vertical split |
Ctrl+w h/j/k/l | Navigate between splits |
:tabnew file | Open file in new tab |
gt / gT | Next / previous tab |
v | Enter Visual mode |
. | Repeat last command |
* | Search for word under cursor |
gg / G | Go to first / last line |
Conclusion
You now have Vim installed and configured on RHEL 10, Rocky Linux 10, or Ubuntu 24.04 with a practical .vimrc, plugin management through vim-plug, and optional LSP support for code intelligence. The combination of NERDTree for file browsing, fzf for fuzzy search, and vim-lsp for autocomplete and diagnostics turns Vim into a capable editing environment for both server administration and development work.
For production use, consider version-controlling your ~/.vimrc and ~/.vim/ directory in a dotfiles repository so you can deploy a consistent Vim setup across all your servers. Pair Vim with database management tools for a complete server administration workflow.