Reprint-Vim's Python editor detailed configuration process (Based on Ubuntu 12.04 LTS)

Source: Internet
Author: User
Tags autoload

Why use Vim to edit py files?

Because in the Linux command line, the lack of graphical interface Ide,vim is the best text editor, and in order to better edit the py text, so configure Vim.

1. Install the full version of Vim

What is the difference between VI and VIM?

In Linux comes with VI editor, and VIM refers to VI improved, which is the VI upgrade version. The difference is that the VI directive and function is more simple than vim, which is why the VI improved.

The VI editor that comes with Ubuntu is Vim.tiny, the most basic function of vim, which is almost equivalent to VI. In Ubuntu, the VI command points to vim.

How do I install vim using apt?

The APT Management Pack is available in Debian and its derived versions of the Linux branch, and APT is the abbreviation for Advanced packaging tools. Ubuntu as a Debian branch, using the APT command Management Pack is very convenient.

When you install a package using the Apt-get command, you will find several packages to choose from: Vim,vim-gnome,vim-gtk,vim-tiny. It is said that vim package is actually vim.basic, this version does not support GUI. The recommended installation is vim-gnome.

APT Search package:

$ Apt-cache Search Package_name

APT installation package:

$ apt-get Install Vim-gnome

When the installation is complete, the VI command points to vim.gnome.

2. Installing Ctags

Ctags is used to support taglist, and ctags can be used to jump between variables.

$ apt-get Install Ctags

3. Installing TagList

First install vim-scripts,vim-scripts with Vim-addon-manager,vim-addon-manager is one of Ubuntu's many plugins manager to manage vim plugins. Install TagList via Vim-addon-manager.

$ apt-get Install vim-scripts$ vim-addons Install TagList

4. Installing Pydiction

Pydiction is used to implement the code completion and syntax hints function. Pydiction cannot be installed via apt and needs to be downloaded and installed by itself.

Download method One: Download the zip package on the VIM website and unzip it yourself. As: download method Two: Download the source code on GitHub, you can use Git to move out to the local, or download the ZIP package to unzip itself, the address is: https://

Pydiction allows vim to automatically complement Python code, whether it's a keyword, a standard library, or a third-party library. It consists mainly of 3 files:

    Python_pydiction.vim:vim plugin file.    complete-dict: A dictionary file that contains the Python keywords and modules. The content referenced by the plug-in is derived from this. A py script that runs this file can add new modules to the Complete-dict dictionary.


How do I install it?

Linux/unix system: Copy the Python_pydiction.vim file to the ~/.vim/after/ftplugin directory. If the directory does not exist, create it and Vim will automatically search in this directory.

Windows system: Copy the Python_pydiction.vim file to the C:\vim\vimfiles\ftplugin directory (assuming your vim installation path is C:\vim)

In addition to the other two files Complete-dict and can be placed in any location you want to place, but in the Ftplugin directory it is best to store only Python_pydiction.vim and should not have other files.

The following are the installation commands that are executed after decompression (my complete-dict and are placed in the ~/.vim directory):

Enter the extracted pydiction directory $ cp after/ftplugin/python_pydiction.vim ~/.vim/after/ftplugin$ CP complete-dict ~/.vim$ CP ~/.vim

5. Edit the configuration file

Edit the ~/.VIMRC file and create it if it does not exist. Add the following content:

 let tlist_auto_highlight_tag=1 let tlist_auto_open=1 let tlist_auto_update=1 let tlist_display_tag_scope=1 let Tl Ist_exit_onlywindow=1 let Tlist_enable_dold_column=1 let tlist_file_fold_auto_close=1 let Tlist_Show_One_File=1 let Tl  Ist_use_right_window=1 let tlist_use_singleclick=1 nnoremap <silent> <F8>:tlisttoggle<cr> filetype Plugin on autocmd FileType python set omnifunc=pythoncomplete#complete autocmd FileType javascrīpt set OMNIFUNC=JAVASCR Iptcomplete#completejs autocmd FileType HTML set omnifunc=htmlcomplete#completetags autocmd FileType CSS Set Omnifunc=cs SCOMPLETE#COMPLETECSS autocmd FileType XML set omnifunc=xmlcomplete#completetags autocmd FileType php set Omnifunc=phpco mplete#completephp autocmd FileType C set omnifunc=ccomplete#complete let g:pydiction_location= ' ~/.vim/tools/pydic Tion/complete-dict ' Set Autoindentset tabstop=4 set shiftwidth=4 set expandtab set number 

FileType plugin on: Indicates that the plug-in is turned on.

Let g:pydiction_location= ' ~/.vim/tools/pydiction/complete-dict ': Write the absolute path to the complete-dict you are storing.

If this is a previous version of Pydiction 1.0, make sure that the VIMRC does not contain the following code:

If have ("autocm")    autocmd FileType python set complete+=k/path/to/pydiction iskeyword+=., (endif "has (" Autocmd ")

6. Attack on. VIMRC

The above-mentioned vim for Python configuration is basically complete, but things can be done a little better, further making your vim more available. (The following attack is not only for Python, but for the perfection of Vim itself.) )

6.1. Installing Pathogen.vim

Introduction: Pathogen.vim is a convenient operation "Runtimepath", "path", "tags" and other plug-ins, installed Pathogen.vim, can be very convenient to download the installation of other VIM plug-ins.

Download: or Https://


First, create two new directories, ~/.vim/autoload and ~/.vim/bundle, under the VIM runtime directory.

$ mkdir-p ~/.vim/autoload ~/.vim/bundle

Second, the copy source package is autoload/pathogen.vim to the ~/.vim/autoload directory.

$ CP Autoload/pathogen.vim ~/.vim/autoload/pathogen.vim

Then, write the following code in the. vimrc file:

Execute Pathogen#infect ()

At this point, the Pathogen.vim installation is complete. After that, all of the Vim plugin catalogs can be extracted to ~/.vim/bundle, which is automatically appended to "Runtimepath".

6.2. Code highlighting

Summary: Highlight the code.



Copy the downloaded Highlight.vim to the ~/.vim/plugin directory.

$ CP Highlight.vim ~/.vim/plugin

Highlight search Results command: Set hlsearch, use command: Hi search View highlighted background color, default brown yellow, change highlight background color command: Hi search guibg=lightblue.

Temporarily close the highlight command: nohlsearch, the command can be abbreviated as: Noh.

You can configure the. VIMRC, use the SPACEBAR to temporarily close the search results highlighted in the. VIMRC write:

: Nnoremap <silent> <Space>:nohlsearch<bar>:echo<cr>

To turn off search results highlighting, use the command: Set Nohlsearch. You can also configure the. VIMRC to use shortcut keys (F4) to quickly turn off and turn on search results highlighting in. VIMRC write:

: Noremap <F4>: Set hlsearch! Hlsearch?<cr>

To turn off search results highlighting by default, write to the. VIMRC:

Set Viminfo^=h

(More reference

(How to highlight a single

6.3. TagList

Summary: Displays a list of labels.

Download: see above.

Installation: See above.

By default, TagList is turned off and written in. VIMRC:

Let Tlist_auto_open=0

Toggle command in normal edit area and tags area: ctrl+w+w.

Tlisttoggle: Switch taglist.

<cr>: jumps to the tag definition.

O: Displays the tag under the cursor in a new window.

U: Update the tag in the TagList window.

S: Change sort order, name sort or line number sort.

X:taglist window zooms out.

+: Open folding, equivalent to Zo.

-: Turn off folding, equivalent to ZC.

*: Open all folds, equal to ZR.

=: All tags are folded to the same ZM.

[[: Jump to previous file.]

]]: Jumps to the next file.

Q: Close the TagList window.

<f1>: Displays Help.


6.4. Folding Code

Summary: Folding python code, Python's class,function, and content tagged in {{{,}}} will be collapsed.



Copy the downloaded Python_fold.vim to the ~/.vim/plugin directory.

Turn off the default collapse command when on, in. VIMRC write:

Set nofoldenable

ZO: Expands a single collapsed area.

Zc: Aggregates a single collapsed area.

Zn: Expands all collapsed areas.

ZN: Aggregates all collapsed areas.


6.5. Nerdtree directory tree

Summary: Open the file directory tree, equivalent to the file browser.



To copy the entire extracted source package to the ~/.vim directory, you need to ensure that the Nerd_tree.vim is located in the ~/.vim/plugin directory, nerd_tree.txt in the ~/.vim/doc directory.

Use <F7> as shortcut key to switch the directory tree in. VIMRC Write:

Map <F7>:nerdtreetoggle<cr>

6.6. Auto-Complete

Summary: Can be used to prompt completion of common words.

Download: or Https://


Copy the Acp.vim to the ~/.vim/plugin directory and copy the Acp.txt to the ~/.vim/doc directory.

"Note" The plugin has a dependent object L9.vim, so you also need to install the L9.vim plugin.

6.7. L9.vim

Summary: Auto-complete autocomplpop dependent libraries.



Place the source package directory under the VIM Runtime directory and make sure that the L9.vim is in the ~/.vim/plugin directory, l9.txt in the ~/.vim/doc directory.

Reprint-Vim's Python editor detailed configuration process (Based on Ubuntu 12.04 LTS)

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