Complete Guide to Vim Plugins: Boost Your Editing Efficiency
As a powerful text editor, Vim’s true charm lies in its extensibility through plugins. In our previous article Vim Configuration Guide: Building an Efficient Text Editing Environment, we covered basic configurations and best practices. This article will detail the installation, configuration, and usage of essential Vim plugins to further enhance your editing efficiency.
I. Plugin Management
Before diving into specific plugins, we need a plugin manager to simplify installation and maintenance. This article uses Vim-plug, a lightweight, fast, and powerful plugin manager.
1.1 Installing Vim-plug
For Linux/macOS systems:
# Install using curl
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# Or install using wget
wget -qO- https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim > ~/.vim/autoload/plug.vim
For Windows systems:
# Run in PowerShell
md -Force ~\vimfiles\autoload
Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' -OutFile ~\vimfiles\autoload\plug.vim
1.2 Basic Usage
Configure plugins in your .vimrc:
" Vim-plug configuration - start
call plug#begin('~/.vim/plugged')
" Add plugins here
Plug 'plugin-author/plugin-name'
" Vim-plug configuration - end
call plug#end()
Common commands:
:PlugInstall- Install plugins specified in the configuration:PlugUpdate- Update plugins:PlugClean- Remove plugins no longer in configuration:PlugUpgrade- Update Vim-plug itself
II. Detailed Plugin Guide
2.1 NERDTree - File Browser
NERDTree is Vim’s most popular file browsing plugin, helping you navigate project directory structures with ease.
2.1.1 Installation
Plug 'preservim/nerdtree'
2.1.2 Basic Configuration
" Map shortcut to toggle NERDTree display
map <leader>n :NERDTreeToggle<CR>
" Show hidden files
let NERDTreeShowHidden = 1
" Manual NERDTreeFind shortcut (find current file in directory structure)
nnoremap <leader>nf :NERDTreeFind<CR>
2.1.3 Usage
- Open/Close NERDTree: Press
<leader>n(default,n) - Find current file in NERDTree: Press
<leader>nf - Navigation operations:
- Use
j/kto move up/down - Press
oto open file or directory - Press
tto open in new tab - Press
sto open in horizontal split - Press
vto open in vertical split - Press
ito view file content in split - Press
cdto set current directory as NERDTree root - Press
Cto set selected directory as root - Press
uto move root up one level - Press
Rto refresh current directory
- Use
- File operations:
- Press
mto open operations menu for create/delete/copy/move - Press
ato add new file or directory - Press
dto delete file or directory - Press
rto rename file or directory
- Press
2.1.4 Advanced Configuration
Auto-open and locate functionality (safer version):
" Optional automatic find function (safer version)
function! s:OpenNERDTreeForFile()
if &buftype == '' && expand('%') != '' && !isdirectory(expand('%'))
try
" Check if NERDTree is loaded
if exists('*NERDTreeFind')
" Check if NERDTree window already exists
if !exists('t:NERDTreeBufName') || bufwinnr(t:NERDTreeBufName) == -1
execute 'NERDTree' . fnameescape(expand('%:p:h'))
else
execute 'NERDTreeFind'
endif
endif
catch
" Ignore any errors
endtry
endif
endfunction
" Enable automatic find if needed
autocmd VimEnter,BufReadPost * call s:OpenNERDTreeForFile()
2.2 CtrlP - File Search
CtrlP is a fast file search plugin that lets you quickly locate and open files by their name.
2.2.1 Installation
Plug 'ctrlpvim/ctrlp.vim'
2.2.2 Basic Configuration
" Configure CtrlP
let g:ctrlp_map = '<c-p>' " Default mapping to Ctrl+p
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'ra' " Auto-set working directory to current file's directory
let g:ctrlp_show_hidden = 1 " Show hidden files
2.2.3 Usage
- Open file search: Press
Ctrl+p - Enter search term: Start typing part of the filename
- Navigate results: Use
Ctrl+j/Ctrl+kor arrow keys to move up/down - Open file: Press
Enterto open in current window, or use these keys to open in different windows:Ctrl+t- Open in new tabCtrl+v- Open in vertical splitCtrl+x- Open in horizontal split
- Switch modes: Press
<F5>in CtrlP window to refresh cache, press<F7>to switch to buffer mode
2.3 SuperTab - Intelligent Code Completion
SuperTab transforms the Tab key into an intelligent code completion trigger, providing context-aware code completion.
2.3.1 Installation
Plug 'ervandew/supertab'
2.3.2 Basic Configuration
" Configure SuperTab
let g:SuperTabDefaultCompletionType = '<c-n>' " Use Vim's built-in completion mechanism
let g:SuperTabRetainCompletionTypeWhileInserting = 1 " Retain completion type while inserting
let g:SuperTabClosePreviewOnPopupClose = 1 " Close preview window when popup closes
2.3.3 Usage
- Press
Tabkey while typing to trigger completion - If multiple completion candidates exist, continue pressing
Tabor use arrow keys to select - Press
Enterto accept the completion suggestion
2.4 Vim-Polyglot - Enhanced Syntax Highlighting
Vim-Polyglot is a syntax package that provides enhanced syntax highlighting, indentation, and code folding for multiple programming languages.
2.4.1 Installation
Plug 'sheerun/vim-polyglot'
2.4.2 Usage
Vim-Polyglot requires no additional configuration after installation. It automatically detects file types and applies appropriate syntax highlighting and indentation rules.
2.5 Vim-GitGutter - Git Integration
Vim-GitGutter displays Git diffs next to line numbers in the Vim editor, giving you a visual indication of which lines in the current file have been modified, added, or deleted.
2.5.1 Installation
Plug 'airblade/vim-gitgutter'
2.5.2 Basic Configuration
" Configure Vim-GitGutter
let g:gitgutter_enabled = 1 " Enable GitGutter
let g:gitgutter_sign_priority = 100 " Ensure GitGutter signs have priority over other signs
let g:gitgutter_sign_added = '+' " Sign for added lines
let g:gitgutter_sign_modified = '~' " Sign for modified lines
let g:gitgutter_sign_removed = '-' " Sign for removed lines
2.5.3 Usage
- View diffs:
+(added),~(modified), or-(removed) signs appear next to line numbers - Navigate diffs:
:GitGutterNextHunk- Move to next diff:GitGutterPrevHunk- Move to previous diff:GitGutterPreviewHunk- Preview current diff:GitGutterStageHunk- Stage current diff:GitGutterUndoHunk- Undo changes in current diff
2.6 Vim-Airline - Enhanced Status Bar
Vim-Airline provides a beautiful, information-rich status bar that displays filename, line number, column number, file format, and more.
2.6.1 Installation
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes' " Theme pack
2.6.2 Basic Configuration
" Configure Vim-Airline
let g:airline_theme = 'gruvbox' " Set theme
let g:airline_powerline_fonts = 1 " Enable Powerline fonts
let g:airline#extensions#tabline#enabled = 1 " Enable tabline
let g:airline#extensions#tabline#formatter = 'default' " Use default formatter
let g:airline#extensions#hunks#enabled = 1 " Show Git diff information
2.6.3 Usage
Vim-Airline takes effect automatically after installation and configuration. The status bar will display:
- Current mode (normal, insert, visual, etc.)
- Filename and file status
- Line and column numbers
- File encoding and format
- Git branch and diff information (when used with GitGutter)
2.7 Vim-EasyMotion - Quick Navigation
EasyMotion allows you to quickly jump to any position in the document by typing 2-3 characters, greatly improving navigation efficiency.
2.7.1 Installation
Plug 'easymotion/vim-easymotion'
2.7.2 Basic Configuration
" Configure EasyMotion
let g:EasyMotion_do_mapping = 0 " Disable default mappings, use custom mappings
" Custom mappings
map <Leader><Leader>f <Plug>(easymotion-overwin-f)
map <Leader><Leader>t <Plug>(easymotion-overwin-t)
map <Leader><Leader>j <Plug>(easymotion-overwin-line-down)
map <Leader><Leader>k <Plug>(easymotion-overwin-line-up)
2.7.3 Usage
- Character search jump: Press
<Leader><Leader>f(default,,f), then type the character to find. Jump markers will appear on the screen; press the corresponding marker character to jump to that position - Line jump: Press
<Leader><Leader>jto search lines downward,<Leader><Leader>kto search lines upward, then type the first character of the target line - Target character jump: Press
<Leader><Leader>tto jump to a position before a specific character
2.8 Tabular - Table Formatting
Tabular is used for aligning text, especially useful for formatting tables, code comments, and other structured content.
2.8.1 Installation
Plug 'godlygeek/tabular'
2.8.2 Usage
- Basic alignment: Select text in visual mode, then run
:Tabularize /delimiter- For example,
:Tabularize /,aligns text by commas - For example,
:Tabularize /=aligns text by equal signs
- For example,
- Custom alignment:
:Tabularize /=/l0- Left align with no space before equal sign:Tabularize /=/r0- Right align with no space before equal sign:Tabularize /=/l1r0- Left field left-aligned, right field right-aligned
- Common scenarios:
- Align assignment statements:
:Tabularize /= - Align comments:
:Tabularize /# - Align tables:
:Tabularize /|
- Align assignment statements:
III. Plugin Combination Tips
3.1 File Operations Workflow
- Use NERDTree (
<leader>n) to browse project structure - Press
oto open files when found - Or use CtrlP (
<C-p>) to directly search and open files - Use SuperTab (
Tab) for code completion while editing - Check modifications using GitGutter (
,~,+,-signs next to line numbers) before saving
3.2 Efficient Navigation Techniques
- Use EasyMotion (
,,f) to quickly jump anywhere in the document - Combine with NERDTreeFind (
,nf) to locate current file in the project - Use Vim-Airline to monitor file information and Git status
3.3 Code Formatting Tips
- Use Tabular to quickly align assignment statements, tables, etc.
- Utilize the syntax highlighting and indentation rules provided by Vim-Polyglot
IV. Configuration Example
Here’s a complete Vim-plug configuration example including all these plugins:
" Vim-plug configuration - start
call plug#begin('~/.vim/plugged')
" Enhanced syntax highlighting
Plug 'sheerun/vim-polyglot'
" File browsing
Plug 'preservim/nerdtree'
" Code completion
Plug 'ervandew/supertab'
" Git integration
Plug 'airblade/vim-gitgutter'
" File search
Plug 'ctrlpvim/ctrlp.vim'
" Status bar
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Quick navigation
Plug 'easymotion/vim-easymotion'
" Table formatting
Plug 'godlygeek/tabular'
" Vim-plug configuration - end
call plug#end()
" NERDTree configuration
map <leader>n :NERDTreeToggle<CR>
let NERDTreeShowHidden = 1
nnoremap <leader>nf :NERDTreeFind<CR>
" CtrlP configuration
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_show_hidden = 1
" SuperTab configuration
let g:SuperTabDefaultCompletionType = '<c-n>'
let g:SuperTabRetainCompletionTypeWhileInserting = 1
" GitGutter configuration
let g:gitgutter_enabled = 1
let g:gitgutter_sign_priority = 100
" Airline configuration
let g:airline_theme = 'gruvbox'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
" EasyMotion configuration
let g:EasyMotion_do_mapping = 0
map <Leader><Leader>f <Plug>(easymotion-overwin-f)
map <Leader><Leader>j <Plug>(easymotion-overwin-line-down)
map <Leader><Leader>k <Plug>(easymotion-overwin-line-up)
V. Conclusion
This article has detailed the installation, configuration, and usage of 8 essential Vim plugins:
- NERDTree - Provides powerful file browsing capabilities
- CtrlP - Enables fast file searching
- SuperTab - Enhances code completion experience
- Vim-Polyglot - Improves syntax highlighting and indentation
- Vim-GitGutter - Integrates Git diff display
- Vim-Airline - Beautifies and enhances the status bar
- Vim-EasyMotion - Enables quick document navigation
- Tabular - Helps format tables and align text
By properly configuring and using these plugins, you can significantly enhance your Vim editing efficiency and experience. Remember, learning Vim is a gradual process - it’s recommended to familiarize yourself with the basics first, then gradually try and master these plugins.
If you want to learn more about basic Vim configurations, please refer to our article Vim Configuration Guide: Building an Efficient Text Editing Environment.
VI. Further Learning Resources
- Vim-plug Official Documentation
- NERDTree Official Documentation
- Vim-EasyMotion Official Documentation
- Vim-Airline Official Documentation
- Mastering NERDTree: A Comprehensive Guide to Vim’s File Explorer
We hope this plugin guide helps you make the most of Vim’s powerful features and create an efficient, personalized text editing environment!
文档信息
- 本文作者:soveran zhong
- 本文链接:https://blog.clockwingsoar.cyou/2025/11/03/vim-plugins-guide-en/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)