Terminal GuideTerminal Guide
vim icon

Vim

Text Editors
macOSLinuxWindows
C

Classic modal text editor with high efficiency and extensibility.

Official Website

Features

Modal EditingPlugin SystemSyntax HighlightingScripting

Installation

Homebrew
brew install vim
APT (Debian/Ubuntu)
apt install vim
Pacman (Arch)
pacman -S vim
DNF (Fedora)
dnf install vim

Why Use Vim?

Vim is a historic text editor that debuted in 1991, achieving fast text editing without taking your hands off the keyboard through its unique paradigm of modal editing.

Blazing Fast Editing Speed

Fast text operations without the mouse through a combination of modal editing and motion commands.

Available Everywhere

Pre-installed on virtually all Unix/Linux environments. Works immediately even when connecting to remote servers via SSH.

Advanced Customization

Highly configurable with .vimrc. Create your own environment with key mappings, color schemes, and plugins.

Rich Plugin Ecosystem

Easy plugin management with vim-plug or Vundle. Add anything you need like file explorer, Git integration, and LSP.

Installation

Installation
# macOS (Homebrew)
brew install vim

# Ubuntu/Debian
sudo apt install vim

# Fedora
sudo dnf install vim

# Arch Linux
sudo pacman -S vim

# Windows (Chocolatey)
choco install vim

# Check version
vim --version

Mode Explanation

Vim is a modal editor. Key behavior changes depending on the current mode.

Normal Mode (Default)

Mode for navigation, text manipulation, and command execution. Vim starts in this mode.

Press Esc to return to this mode from other modes

Insert Mode

Mode for typing text. Type characters just like in a normal editor.

Press i, I, a, A, o, or O to enter

Visual Mode

Mode for selecting text. Perform operations (delete, copy, replace, etc.) on selected ranges.

Press v (character), V (line), or Ctrl+v (block) to enter

Command-line Mode

Mode for executing Ex commands. Perform file saving, exiting, search/replace, etc.

Press : to enter

Basic Operations

Basic Operations
# Open a file
vim filename.txt

# Open a file and jump to a specific line
vim +10 filename.txt

# Open in read-only mode
vim -R filename.txt

# Open in diff mode
vim -d file1.txt file2.txt

# Open multiple files (tabs)
vim -p file1.txt file2.txt

# Open multiple files (split)
vim -o file1.txt file2.txt   # horizontal split
vim -O file1.txt file2.txt   # vertical split

Frequently Used Commands

Movement Commands (Normal Mode)

KeyDescription
h j k lMove left, down, up, right
w / bMove to next / previous word
0 / $Move to beginning / end of line
gg / GMove to beginning / end of file
:10Jump to line 10
Ctrl+d / Ctrl+uScroll half page down / up
%Move to matching bracket

Edit Commands

KeyDescription
i / aInsert before / after cursor
I / AInsert at beginning / end of line
o / OInsert new line below / above
x / XDelete character at / before cursor
ddDelete line (cut)
yyCopy line (yank)
p / PPaste after / before cursor
u / Ctrl+rUndo / Redo
.Repeat last command

File Operations (Command-line Mode)

CommandDescription
:wSave
:qQuit
:wq or :xSave and quit
:q!Quit without saving
:e filenameOpen file
/patternForward search
:%s/old/new/gReplace all

Configuration File

Write Vim configuration in ~/.vimrc.

~/.vimrc
" Basic settings
set nocompatible              " Disable Vi compatibility mode
set encoding=utf-8            " Character encoding
set fileencoding=utf-8        " File character encoding
set number                    " Show line numbers
set relativenumber            " Show relative line numbers
set cursorline                " Highlight cursor line
set showmatch                 " Highlight matching brackets
set wildmenu                  " Enable command completion

" Indentation settings
set tabstop=4                 " Tab width
set shiftwidth=4              " Auto-indent width
set expandtab                 " Convert tabs to spaces
set autoindent                " Auto-indent
set smartindent               " Smart indent

" Search settings
set hlsearch                  " Highlight search results
set incsearch                 " Incremental search
set ignorecase                " Case-insensitive search
set smartcase                 " Case-sensitive if uppercase present

" Display settings
syntax on                     " Syntax highlighting
set termguicolors             " True color support
set background=dark           " Background color
set laststatus=2              " Always show status line
set ruler                     " Show cursor position

" Backup settings
set nobackup                  " Don't create backup files
set noswapfile                " Don't create swap files
set undofile                  " Enable undo file
set undodir=~/.vim/undo       " Undo file directory

" Key mappings
let mapleader = " "           " Set leader key to space
nnoremap <leader>w :w<CR>     " Space+w to save
nnoremap <leader>q :q<CR>     " Space+q to quit
nnoremap <C-h> <C-w>h         " Window navigation
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" Clear search highlight with Esc
nnoremap <Esc><Esc> :nohlsearch<CR>

" Share clipboard
set clipboard=unnamedplus

Plugin Management (vim-plug)

vim-plug is the most popular Vim plugin manager.

Installing vim-plug

Installation
# Unix/Linux/macOS
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

# Windows (PowerShell)
iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |
    ni $HOME/vimfiles/autoload/plug.vim -Force

Plugin Configuration Example

~/.vimrc
" vim-plug initialization
call plug#begin('~/.vim/plugged')

" File explorer
Plug 'preservim/nerdtree'

" Fuzzy finder
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

" Git integration
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'

" Status line
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

" Color schemes
Plug 'morhetz/gruvbox'
Plug 'dracula/vim', { 'as': 'dracula' }

" Enhanced syntax highlighting
Plug 'sheerun/vim-polyglot'

" Auto-completion (parentheses, etc.)
Plug 'jiangmiao/auto-pairs'

" Comment toggling
Plug 'tpope/vim-commentary'

" Surround operations
Plug 'tpope/vim-surround'

" LSP (Language Server)
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'

call plug#end()

" Plugin configuration
" NERDTree
nnoremap <leader>n :NERDTreeToggle<CR>

" fzf
nnoremap <leader>f :Files<CR>
nnoremap <leader>b :Buffers<CR>
nnoremap <leader>g :Rg<CR>

" Color scheme
colorscheme gruvbox

Plugin Commands

vim-plug Commands
:PlugInstall    " Install plugins
:PlugUpdate     " Update plugins
:PlugClean      " Remove unused plugins
:PlugUpgrade    " Update vim-plug itself
:PlugStatus     " Check plugin status

Tips

  • Run vimtutor for an interactive tutorial. Vim beginners should definitely try this once.
  • Learn operator + motion combinations. For example, d (delete) + w (word) = delete word.
  • Text objects like ciw (change inner word) are very efficient.
  • Automate repetitive tasks with macros (press q to start recording).
  • Access comprehensive help with :help command. Search for specific topics with :help keyword.
  • Run :checkhealth periodically to check for environment issues (originated from Neovim but works partially in Vim).
  • You can also get familiar with Vim keybindings using VSCode's Vim extension.
Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More