Fundamentals 10 min read

Vim Configuration Guide for Python Development

This guide provides a comprehensive Vim setup for Python development, covering .vimrc basics, window splitting, code folding, one‑key execution, plugin management with Vundle, auto‑completion tools, syntax checking, color schemes, file navigation, and useful shortcuts.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Vim Configuration Guide for Python Development

This article explains how to configure Vim as an efficient Python development environment. It starts with creating or editing the ~/.vimrc file and adding essential settings such as set nocompatible , line numbers, syntax highlighting, and UTF‑8 encoding.

It then describes window management commands ( :vs , :sp , :new , :vnew ) and how to set splitbelow and splitright for new windows, plus key mappings ( Ctrl‑w‑j/k/l/h or custom nnoremap shortcuts) for quick navigation.

Code folding is enabled with set foldmethod=indent and set foldlevel=99 , using zc to create folds and za (or the space bar) to toggle them.

A one‑key Python runner is added by mapping map <F5> :call RunPython()<CR> and defining the RunPython() function that executes the current buffer with python when the filetype is Python.

Plugin management is handled by Vundle: install Vundle via git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim , then list plugins between call vundle#begin() and call vundle#end() . Examples include Plugin 'VundleVim/Vundle.vim' , Plugin 'Valloric/YouCompleteMe' , Plugin 'vim-scripts/indentpython.vim' , Plugin 'nvie/vim-flake8' , Plugin 'altercation/vim-colors-solarized' , Plugin 'scrooloose/nerdtree' , Plugin 'Lokaltog/vim-powerline' , Plugin 'Yggdroot/indentLine' , Plugin 'tell-k/vim-autopep8' , Plugin 'jiangmiao/auto-pairs' , Plugin 'kien/ctrlp.vim' , Plugin 'rking/ag.vim' , and Plugin 'tpope/vim-fugitive' .

After installing plugins, you may need to compile YouCompleteMe with cd ~/.vim/bundle/YouCompleteMe && ./install.py --clang-completer and configure its options (e.g., let g:ycm_min_num_of_chars_for_completion = 2 ).

Additional configurations include enabling syntax enable , setting the Solarized or Zenburn color scheme, adding NERDTree shortcuts ( map <C-n> :NERDTreeToggle<CR> ) and ignore patterns, and toggling indentation guides with :IndentLinesToggle . Finally, shortcuts for auto‑formatting ( autocmd FileType python noremap <buffer> <F8> :call Autopep8()<CR> ) and other productivity tools are provided.

PythonDevelopment EnvironmentVimpluginsauto completionCode FoldingVundle
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login 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.