Fundamentals 14 min read

Master Vim: Essential Configurations, Plugins, and Productivity Hacks

This guide walks you through setting up Vim with basic configurations, window splitting, code folding, one‑click Python execution, and a curated set of powerful plugins like Vundle, YouCompleteMe, NerdTree, and color schemes to boost your development workflow.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Vim: Essential Configurations, Plugins, and Productivity Hacks

Basic Configuration

Vim settings are stored in ~/.vimrc. If the file does not exist, create it:

cd ~
 touch .vimrc

Typical initial settings:

set nocompatible "disable vi compatibility mode
set number "show line numbers
set nowrap "no line wrapping
set showmatch "highlight matching brackets
set scrolloff=3 "keep 3 lines visible above/below cursor
set encoding=utf-8 "file encoding
set fenc=utf-8 "file encoding
set mouse=a "enable mouse
set hlsearch "highlight search results
syntax on "enable syntax highlighting

Add PEP8 support for Python files:

au BufNewFile,BufRead *.py \
    set tabstop=4 "tab width
    set softtabstop=4
    set shiftwidth=4
    set textwidth=79 "max line length
    set expandtab "convert tabs to spaces
    set autoindent "automatic indentation
    set fileformat=unix "unix line endings

Window Splitting

Use the following commands to split windows: :vs or :vsplit – vertical split :vs filename – open file in a new vertical split :sp, :sv or :split – horizontal split :sp filename – open file in a new horizontal split :new – new file with vertical split :vnew – new file with horizontal split

To open new windows on the right or bottom, add:

set splitbelow
set splitright

Switch between windows with: Ctrl-w-j – move to the window below Ctrl-w-k – move to the window above Ctrl-w-l – move to the window on the right Ctrl-w-h – move to the window on the left

Map these to single keys if desired:

nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

Code Folding

Enable folding based on indentation:

set foldmethod=indent
set foldlevel=99

Use zc to create a fold and za to toggle it. Map space to za for convenience:

nnoremap <space> za

One‑Click Python Execution

Map F5 to run the current Python buffer:

map <F5> :call RunPython()<CR>
func! RunPython()
  if &filetype == 'python'
    exec "!time python2.7 %"
  endif
endfunc

Plugins

The most common plugin manager is Vundle, which uses Git to manage other plugins.

Vundle Installation

Clone Vundle:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

If ~/.vim/bundle does not exist, create it:

cd ~
mkdir .vim
cd .vim
mkdir bundle

Add the following to the top of .vimrc:

set nocompatible "required
filetype off "required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" List plugins between begin() and end()
Plugin 'VundleVim/Vundle.vim'
" ... other Plugin lines ...
call vundle#end() "required
filetype plugin indent on "required

Install a plugin (e.g., indentpython.vim) by adding: Plugin 'vim-scripts/indentpython.vim' Then run :PluginInstall inside Vim or from the command line:

vim +PluginInstall +qall

YouCompleteMe

YouCompleteMe provides powerful auto‑completion but requires compilation. Install dependencies on Ubuntu:

sudo apt-get install build-essential cmake
sudo apt-get install python3-dev python3

Add to .vimrc: Plugin 'Valloric/YouCompleteMe' Compile:

cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer

Typical YCM options:

let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_python_binary_path = 'python'
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_autoclose_preview_window_after_completion=1

Toggle YCM auto‑trigger:

let g:ycm_auto_trigger = 0 "off
let g:ycm_auto_trigger = 1 "on

Lightweight Completion (completor.vim)

Install: Plugin 'maralla/completor.vim' Install jedi for Python: pip install jedi Configure:

let g:completor_python_binary = '/path/to/python'

Indentation Plugin

Install indentpython.vim for automatic Python indentation:

Plugin 'vim-scripts/indentpython.vim'

Syntax Checking (syntastic + flake8)

Install:

Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'

Run :F7 to invoke flake8 checks.

Color Schemes

Solarized (dark or light): Plugin 'altercation/vim-colors-solarized' Enable:

syntax enable
set background=light "or dark
colorscheme solarized

Switch based on GUI mode:

if has('gui_running')
  set background=light
else
  set background=dark
endif

Zenburn alternative: Plugin 'jnurmine/Zenburn' Toggle between Solarized and Zenburn:

if has('gui_running')
  set background=light
  colorscheme solarized
else
  set background=dark
  colorscheme Zenburn
endif

NerdTree

File explorer tree: Plugin 'scrooloose/nerdtree' Toggle with Ctrl‑n: map <C-n> :NERDTreeToggle<CR> Ignore temporary files: let NERDTreeIgnore=['~$','\.pyc$','\.swp$'] Add Git status support: Plugin 'Xuyuanp/nerdtree-git-plugin' Use tabs for NerdTree:

Plugin 'jistr/vim-nerdtree-tabs'

vim‑powerline

Status line enhancement:

Plugin 'Lokaltog/vim-powerline'

IndentLine

Show vertical indentation guides: Plugin 'Yggdroot/indentLine' Toggle with :IndentLinesToggle.

vim‑autopep8

Automatic PEP8 formatting:

$ pip install autopep8
Plugin 'tell-k/vim-autopep8'

Map F8 to format:

autocmd FileType python noremap <buffer> <F8> :call Autopep8()<CR>

auto‑pairs

Auto‑close brackets and quotes:

Plugin 'jiangmiao/auto-pairs'

ctrlp.vim

Fuzzy file finder (press Ctrl‑p in normal mode):

Plugin 'kien/ctrlp.vim'

ag.vim

Search using The Silver Searcher:

apt-get install silversearcher-ag   "or brew install the_silver_searcher
Plugin 'rking/ag.vim'

Search with:

:Ag [options] {pattern} [{directory}]

vim‑fugitive

Git integration inside Vim:

Plugin 'tpope/vim-fugitive'
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DevelopmentConfigurationproductivityVimPlugins
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.