Vim as Python ide on Windows

Source: Internet
Author: User

Download and install python.

Download Vim from the vim website.Self-installing executable.

 

Edit the vim configuration file _ vimrc

Copy the stuff in vimrc_example to _ vimrc

Remove source $ vimruntime/vimrc_example.vim from _ vimrc.

 

Set Chinese support

"Sets automatic encoding recognition and displays Chinese quotation marks
"Set fileencodings = UTF-8, cp936, big5, EUC-JP, EUC-KR, Latin1, ucs-bom
Set fileencodings = UTF-8, GBK
Set ambiwidth = double

 

Set colorscheme. I chose desert. You can see other color scheme in gvim's edit --> color scheme.

"Colorscheme
Colorscheme desert

 

Set Tab insertion space, indentation, deletion key deletion indent, page text width

"Allow the return key deletion and Tab operations
Set smartindent
Set smarttab
Set expandtab
Set tabstop = 4
Set softtabstop = 4
Set shiftwidth = 4
Set backspace = 2
Set textwidth = 79

 

Enable mouse and line number

"Enable mouse
Set mouse =

"Enable row number
Set nu

 

After completing the preceding steps, use gvim to open the Python code.

 

Enable the code complementing function of omni-completion. The components of this series are installed with vim. By the way, I have added support for Ruby and other languages. Press ctrl-X and Ctrl-O to complete the code.

Modify _ vimrc as follows:

Code

"Auto-completion
Filetype plugin indent on
Set completeopt = longest, menu
"Use the menu-style match list when the auto-completion command is executed.
Set wildmenu
Autocmd filetype Ruby, eruby set omnifunc = rubycomplete # complete
Autocmd filetype Python set omnifunc = pythoncomplete # complete
Autocmd filetype JavaScript set omnifunc = javascriptcomplete # completejs
Autocmd filetype HTML set omnifunc = htmlcomplete # completetags
Autocmd filetype CSS set omnifunc = csscomplete # completecss
Autocmd filetype XML set omnifunc = xmlcomplete # completetags
Autocmd filetype Java set omnifunc = javacomplete # complet

Omni-completion implements Code Completion

 

Omni-completion can implement partial code complementing functions, but it is not very complete. Therefore, we enable pydiction, provide richer code complementing functions, and press tab to complete the code.

Download pydiction and decompress the package. Copy python_pydiction.vim and complete-dict to the ftplugin directory and modify _ vimrc.

"Pydiction
Let G: pydiction_location = 'C: \ Program Files \ Vim \ vim73 \ ftplugin \ complete-dict

Now, you can press the tab key to complete the code,

 

Next we need to analyze the source code tool ctags, download the ctags for Windows website from the website, decompress the file, and then upload the ctags.exe to a certain place to ensure that the windows path contains this directory.

Open the source code file and click the buildtags button on gvim. Or manually execute the ctags-R command in the source code directory on the console. We can find that the tags file is generated in the current directory. This is what we need. We can press crtl +] on the method, and VIM will help you find the method definition.

 

Next we need to use this file to view the source code. We need another plug-in taglist, which can be used with ctags to efficiently view the source code. Download the taglist and decompress it to the doc and plugin directories and copy these two directories to your vim installation directory (my path is c: \ Program Files \ Vim \ vim73 ), overwrite the original directory (do not worry that overwriting will not affect existing items). Modify _ vimrc as follows:

"Taglist
Let tlist_show_one_file = 1
Let tlist_exit_onlywindow = 1

We need to create the tags directory for vim and execute the command in VIM: Set tags = path of your code \ tags, if you keep using the same code path, you can write it to _ vimrc. For example

D: \ vimtest configuration is as follows:

 

"Tags
Set tags = D: \ vimtest \ tags

 

Then execute tlist in VIM to open the taglist window. For example, in the left window, click the method. You can see that the cursor on the right will automatically jump to the method you clicked.

 

Next we will add the file browsing function. Download winmanager, compress it, and put it in the plugin directory. The configuration below shows both fileexplorer and taglist

"Winmanager
Let G: winmanagerwindowlayout = 'fileexplorer | taglist'
Nmap wm: wmtoggle <CR>

Enter the WM command below to see that the upper left is fileexplorer and the lower left is taglist.

 

Enable cssag for more advanced source code analysis and support Reverse Lookup

Download the available version of fuse in Windows.

Download cscope_maps.vim and put it in the vim plugin directory.

Modify _ vimrc to display the search result in the quickfix window instead of the main window.

"Cscope show in quickfix
Set cscopequickfix = s-, C-, D-, I-, T-, e-

Now, the configuration is complete. Let's see how to use it. Enter: Help if_cscop.txt in VIM to view the help for cscope.

After reading the document, we can enter the command CS find C Foo in VIM to find out where the foo method has been called.

Cscope_maps.vim maps some keyboard shortcuts, so we can use the search function quickly.

I prefer to use Ctrl + \ to move the cursor over the content you want to search for. Then, enter Ctrl + \ and enter C quickly to view the search result in the quickfix form. If there are multiple results, you can enter the command: CW to expand the quickfix form. (This quick operation may be awkward for the first time. Just try it several times)

Below is a result of my search

 

Enable minibufexplorer and manage the vim buffer (buffer zone) to quickly switch between multiple files simultaneously edited.

Edit _ vimrc as follows:

 

"Minibufexplorer
Let G: minibufexplmapwindownavvim = 1
Let G: minibufexplmapwindownavarrows = 1
Let G: minibufexplmapctabswitchbufs = 1
Let G: minibufexplmodseltarget = 1

 

 

After configuration, the minibufexplorer window appears. Click the file name above to quickly switch between different files.

 

Enable grep and find in Project

Grep is a command in Linux. If you are not familiar with grep, you can read the grep documentation.

Download and install grep for Windows

Download the vim grep plug-in. Place grep. Vim In the plugin directory.

Configure _ vimrc and set F3 as the shortcut key

"Grep
Nnoremap <silent> <F3>: grep <CR>

Place the cursor on the content you want to search. Press F3 to see search for pattern: XXX. Press enter to Display Search in files and enter *. PY, only find the Python source code file, press enter to view the search results. See

 

Enable vimpdb to debug Python programs.

Download vimpdb, decompress it, copy vimpdb. py, and vimpdb. Vim to plugin.

Run the Python code file with vim, press F5, and then press f2 to set the breakpoint. After the breakpoint is run, press F12 to view the stack trace and F3 to view the variables and parameter values.

For more advanced usage, see the documentation.

 

Enable ropevim to refactor the python Program

Download rope, ropemode, and ropevim, decompress them, open the console, CD to the decompressed directory, and execute Python setup. py install.

Then copy the ropevim. Vim file to the plugin directory. In this way, the installation is complete. Try refactoring a class name, place the cursor on the class name, press Ctrl-C, and then press R twice.

You can see that the quickfix form requires you to enter new name:, enter a new name, and press Enter. The reconstruction is complete. For example

 

Python code check

Create a python directory under the ftplugin directory of vim.

Download pyflakes, decompress the package, and copy the pyflakes. Vim file and the pyflakes directory to the ftplugin \ Python directory.

Open a problematic Python source code file and execute the command: CC to check the Code. For example, two errors are found.

 

Now I have finished writing it. I am so tired. I finally put a big picture to show the overall effect.

 

Reference:

How to convert Vim into an IDE programming environment)

Vim as Python ide

There are many references. I will not list them one by one.

From: http://www.cnblogs.com/renrenqq/archive/2010/09/09/1813669.htmlblog address: http://home.cnblogs.com/u/renrenqq

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.