Vim editor under Python2.0 Auto-complete

Source: Internet
Author: User

Python automatically complements all of the vim editing and Python interactive modes, and below describes how to implement tab completion in these 2 situations.

One, vim python automatic completion plug-in: pydiction

You can implement the following Python code auto-completion:

    1. Simple python keyword completion
    2. Python function completion with parentheses
    3. Python Module completion
    4. Python module inner function, variable completion
    5. From module import sub-module complement

To start AutoComplete for vim, you need to download the plugin at the following address:
http://vim.sourceforge.net/scripts/script.php?script_id=850
Https://github.com/rkulla/pydiction

Installation configuration:

wget https://github.com/rkulla/pydiction/archive/master.zipunzip-q mastermv pydiction-master pydictionmkdir-p ~/. Vim/tools/pydictioncp-r pydiction/after ~/.VIMCP pydiction/complete-dict ~/.vim/tools/pydiction

Ensure that the file structure is as follows:

# tree ~/.vim/root/.vim├──after│   └──ftplugin│       └──python_pydiction.vim└──tools    └──pydiction        └── Complete-dict

Create a ~/.VIMRC to make sure the contents are as follows:

# cat ~/.vimrcfiletype plugin Onlet g:pydiction_location = ' ~/.vim/tools/pydiction/complete-dict '
#以上内容如果没有则需要手工添加

Use Vim to edit a py file, import os., this time should appear prompt, prove success, such as

Second, the Python Interactive mode tab auto-completion
Create the file as follows:

# cat ~/.pythonstartup# vim startup.py#!/usr/bin/env pythonimport sysimport readlineimport rlcompleterimport Atexitimport os# tab completionreadline.parse_and_bind (' Tab:complete ') # History filehistfile = Os.path.join ( os.environ[' HOME '], '. Pythonhistory ') Try:    readline.read_history_file (histfile) except IOError:    Passatexit.register (Readline.write_history_file, histfile) del os, Histfile, ReadLine, Rlcompleter1echo ' export Pythonstartup=~/.pythonstartup ' >> ~/.bash_profile

If the above method does not take effect, you can write the above content to startup.py and add it to Python's configuration folder/usr/lib64/python27/

Import the startup module each time you enter interactive mode

Re-login to the shell, enter the python command into interactive mode, you can use the TAB key to complete the completion. Such as:

Vim editor under Python2.0 Auto-complete

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.