I've tried several editors for writing Python, such as VSCode, Atom, Sublime, PyCharm, and even Bluefish. The issues I experienced bothered me, like Atom too fat, Sublime complicated plugin configuration, PyCharm uncertain runtime path... Eventually I decided to stay with my love, vi and vim that I've used for almost 20 years.
There are multiple ways to configure VIM as Python IDE, through vundle, pip3 install, then I figured to have plugins managed by git and vundle, the plugin manager. Therefore I write this document.
Notes:
- This doc is written with Python3, not tested with Python2
- Python's plugin are very various and many. I choose some as my personal experience only
- Using Fedora 36 with default
vim, at the moment when writing this doc
Personally I think that the best practice to Enable VIM as Python IDE is https://realpython.com/vim-and-python-a-match-made-in-heaven/ with credits. And I also fixed 2 defects in configuration, supplied by RealPython.com, with comment starting with Jeff's Fix
My current ~/.vimrc can be downloaded ./vimrc
vim --versionSupposedly you can see
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 30 2017 18:21:38)
...
Huge version with GTK3 GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_sgr +tag_old_static
...
+conceal +libcall +profile +viminfo
+cryptv +linebreak -python +vreplace
+cscope +lispindent +python3 +wildignorethat indicates this pre-built vim (version 8.0) supports python3, but not python2. Weird but this is default from Debian Stretch 9.6, with vim-tiny completely removed
And verify in vim
:python import sys; print(sys.version)git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vimTouch ~/.vimrc and copy the following into it. Remember to execute :wq and :PluginInstall each time after adding new plugin(s) in ~/.vimrc
set nocompatible " required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)
Plugin 'tmhedberg/SimpylFold'
let g:SimpylFold_docstring_preview=1
" Auto-indentation
Plugin 'vim-scripts/indentpython.vim'
" Jedi-vim
Plugin 'davidhalter/jedi-vim'
" Auto-complete
Plugin 'Valloric/YouCompleteMe'
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
" Syntax checking/ highlighting
Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'
let python_highlight_all=1
syntax on
" Color schemes
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
" File browsing
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
" Super searching
Plugin 'kien/ctrlp.vim'
" Git integration
Plugin 'tpope/vim-fugitive'
" Powerline
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" Color scheme
if has('gui_running')
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
" Split Layouts
set splitbelow
set splitright
" split navigations
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>
" Enable folding
set foldmethod=indent
set foldlevel=99
" Enable folding with the spacebar
nnoremap <space> za
" Jeff's Fix: there must be a "|" to isolate each "set"
au BufNewFile,BufRead *.py,*.md
\ set tabstop=4 |
\ set softtabstop=4 |
\ set shiftwidth=4 |
\ set textwidth=79 |
\ set expandtab |
\ set autoindent |
\ set fileformat=unix
" Jeff's Fix: there is NO whitespace between *.js and *.html, etc
au BufNewFile, BufRead *.js,*.html,*.css,*.yml,*.yaml
\ set tabstop=2 |
\ set softtabstop=2 |
\ set shiftwidth=2
" Flagging Unnecessary Whitespace
au BufRead, BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
" UTF-8 Support
set encoding=utf-8Reference > https://ycm-core.github.io/YouCompleteMe/#linux-64-bit
Clone the code, then
If you want auto-complete for Go, a pre-requisite is to install go and go-lang
Or for Python only,
cd ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive
python3 install.pyBased on jedi-vim and reference to https://github.com/davidhalter/jedi-vim
Clone the code
git clone --recursive https://github.com/davidhalter/jedi-vim.git ~/.vim/bundle/jedi-vimThen place the following in ~/.vimrc, execute install with :PluginInstall
Plugin 'davidhalter/jedi-vim'