Vim
Classic modal text editor with high efficiency and extensibility.
Official WebsiteFeatures
Installation
brew install vimapt install vimpacman -S vimdnf install vimWhy 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
# 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 --versionMode 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 modesInsert Mode
Mode for typing text. Type characters just like in a normal editor.
Press i, I, a, A, o, or O to enterVisual Mode
Mode for selecting text. Perform operations (delete, copy, replace, etc.) on selected ranges.
Press v (character), V (line), or Ctrl+v (block) to enterCommand-line Mode
Mode for executing Ex commands. Perform file saving, exiting, search/replace, etc.
Press : to enterBasic 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 splitFrequently Used Commands
Movement Commands (Normal Mode)
| Key | Description |
|---|---|
h j k l | Move left, down, up, right |
w / b | Move to next / previous word |
0 / $ | Move to beginning / end of line |
gg / G | Move to beginning / end of file |
:10 | Jump to line 10 |
Ctrl+d / Ctrl+u | Scroll half page down / up |
% | Move to matching bracket |
Edit Commands
| Key | Description |
|---|---|
i / a | Insert before / after cursor |
I / A | Insert at beginning / end of line |
o / O | Insert new line below / above |
x / X | Delete character at / before cursor |
dd | Delete line (cut) |
yy | Copy line (yank) |
p / P | Paste after / before cursor |
u / Ctrl+r | Undo / Redo |
. | Repeat last command |
File Operations (Command-line Mode)
| Command | Description |
|---|---|
:w | Save |
:q | Quit |
:wq or :x | Save and quit |
:q! | Quit without saving |
:e filename | Open file |
/pattern | Forward search |
:%s/old/new/g | Replace all |
Configuration File
Write Vim configuration in ~/.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=unnamedplusPlugin Management (vim-plug)
vim-plug is the most popular Vim plugin manager.
Installing vim-plug
# 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 -ForcePlugin Configuration Example
" 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 gruvboxPlugin Commands
:PlugInstall " Install plugins
:PlugUpdate " Update plugins
:PlugClean " Remove unused plugins
:PlugUpgrade " Update vim-plug itself
:PlugStatus " Check plugin statusTips
- •Run
vimtutorfor 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
qto start recording). - •Access comprehensive help with
:helpcommand. Search for specific topics with:help keyword. - •Run
:checkhealthperiodically 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.