Python tab completions

Source: Internet
Author: User

Way One:

Ubuntu just installed the command Line Input command is not automatic completion, you can make the following changes to add command line command auto-completion function.
Modify the /etc/bash.bashrc file

  if [-f/usr/share/bash-completion/bash_completion];    Then /usr/share/bash-completion/bash_completion  elif [-f/etc/bash_completion];    Then /etc/bash_completion  fi

Uncomment the above lines of code, save it, and use auto-completion when you open the command line again.

Mode two

1. Get the Python directory "I'm using a 64-bit Ubuntu system"

  1. [~$]python
  2. Python 2.7. 3 (default, APR , £ º)
  3. [GCC 4.6. 3] on linux2
  4. Type "Help", "copyright", "credits" or "license" for more information.
  5. >>> Import sys
  6. >>> Sys.path
  7. [', '/usr/lib/python2.7 ', '/usr/lib/python2.7/plat-linux2 ', '/usr/lib/python2.7/lib-tk ', '/ Usr/lib/python2.7/lib-old ',
  8. '/usr/lib/python2.7/lib-dynload ', '/usr/local/lib/python2.7/dist-packages ', '/usr/lib/python2.7/ Dist-packages ',
  9. '/usr/lib/python2.7/dist-packages/pil ', '/usr/lib/python2.7/dist-packages/gst-0.10 ', '/usr/lib/ Python2.7/dist-packages/gtk-2.0 ',
  10. '/usr/lib/python2.7/dist-packages/ubuntu-sso-client ', '/usr/lib/python2.7/dist-packages/ubuntuone-client ',
  11. '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel ', '/usr/lib/python2.7/dist-packages/ Ubuntuone-couch ',
  12. '/usr/lib/python2.7/dist-packages/ubuntuone-installer ', '/usr/lib/python2.7/dist-packages/ Ubuntuone-storage-protocol ']
  13. >>>


From the above, I see that the path of Python on my computer is/usr/lib/python2.7.

2. Switch to the directory to write a startup.py script, the script directory is to process the Python <tab> events, the script content is as follows

  1. #!/usr/bin/python
  2. # Python startup file
  3. Import Sys
  4. Import ReadLine
  5. Import Rlcompleter
  6. Import atexit
  7. Import OS
  8. # tab Completion
  9. Readline.parse_and_bind (' tab:complete ')
  10. # History File
  11. Histfile = Os.path.join (os.environ[' HOME '), '. Pythonhistory ')
  12. Try
  13. Readline.read_history_file (Histfile)
  14. Except IOError:
  15. Pass
  16. Atexit.register (Readline.write_history_file, Histfile)
  17. Del os, Histfile, ReadLine, Rlcompleter

3. Switch to your home directory

    1. [/USR/LIB/PYTHON2.7$]CD
    2. [~$]vi. BASHRC

4. Add Environment variables

    1. #for python
    2. Export pythonstartup=/usr/lib/python2.7/startup.py

5. Configure environment variables to take effect

[Plain]View Plaincopyprint?
    1. [~$]source. BASHRC

automatic completion in vim

1. Download the plugin:

: http://download.csdn.net/detail/loovejava/6284225

2. Copy to the appropriate directory

    1. Unzip Pydiction-1.2.1.zip
    2. CP Python_pydiction.vim/usr/share/vim/vim73/ftplugin
    3. Mkdir/usr/share/vim/vim73/pydiction
    4. CP complete-dict/usr/share/vim/vim73/pydiction/
    5. CP pydiction.py/usr/share/vim/vim73/pydiction/


3. Modify the VIM configuration file

      1. Let g:pydiction_location = '/usr/s

Python tab completions

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.