Home > Article > Backend Development > How to use tab for python code completion in vim
Pydiction allows you to implement TAB code completion in Vim. The content that can be completed includes: standard, custom, and third-party modules and packages. Plus keywords, BIFs, and strings.
Pydiction consists of 3 main files:
python_pydiction.vim -- This file is Vim's plugin file, which implements the TAB completion function of Python files.
complete-dict -- This file is Vim's dictionary file, which contains information such as Python keywords and module structure. Is the reference file that the plugin looks for when completing.
pydiction.py -- (Optional) This file is a Python script file used to generate dictionary files. More TAB-completable modules can be added by executing this script.
Usage
======
Enter part of the Python keyword, module name, attribute or method name in Vim, and then press the Tab key to pop up the completion information.
For example, enter
os.p
will pop up
os.pardir
os.path
os.pathconf(
os.pathconf_names
os.pathsep
os.pipe(
. ..
If you find that the results you get in the TAB completion menu are not what you want, one possible reason is that you have not set Vim to ignore case. You can set it through ":set noic".
【How to install】
Under UNIX/LINUX, put python_pydiction.vim into ~/.vim/after/ftplugin/. If the directory does not exist, create it manually. Vim will automatically search for relevant files in this directory. Do not put other files except python_pydiction.vim into this directory.
Add the following field to your vimrc file to enable ftplugins:
filetype plugin on
Then make sure to set "g:pydiction_location" to point to where you placed it The full path of the complete-dict file, for example
let g:pydiction_location = 'C:/vim/vimfiles/ftplugin/pydiction/complete-dict'
You can refer to
# unzip pydiction-1.2.zip
# cp python_pydiction.vim /usr/share/vim/vim70/ftplugin
# mkdir /usr/share/vim/vim70/pydiction
# cp complete-dict pydiction.py /usr/share/vim/vim70/pydiction/
# vi ~/.vimrc
...
# Add
let g:pydiction_location = '/usr/share/vim/vim70/pydiction/complete-dict'
let g:pydiction_menu_height = 20
Open the python script file and press the TAB key to activate the auto-complete menu