Python is my favorite programming language, and vim is also my most commonly used editor, so it is necessary to better configure vim to edit the Python source program. Next, let's talk about some of the configuration skills I learned. Most of the following configurations are implemented by modifying the _ vimrc file, which exists in the vim installation directory in Windows. 1. Quick Call environment
Python is my favorite programming language, and vim is also my most commonly used editor, so it is necessary to better configure vim to edit the Python source program. Next, let's talk about some of the configuration skills I learned. Most of the following configurations are implemented by modifying the _ vimrc file, which exists in the vim installation directory in Windows.
1Environment variables used for quick calls
I am used to adding the executable file PATH of vim to the PATH environment variable, so that we can easily start vim when programming in the console.
2, Start the console in the current path
In many cases, you need to start a cmd window in the current path to debug the program in the console, and some paths that are quite deep or contain a large number of Chinese characters make us very angry. Therefore, you can write a simple batch file to start the cmd window in the current folder.
@ Echo off
Cmd.
Save as example here. bat. In this way, copy upload here. bat to the desired folder and double-click the batch file to open the desired cmd window. the current path is also the path of the folder, which is very convenient.
3Disable backup
After installation, vim automatically provides the backup function. Once a file is modified, it will generate ~ The backup file of filename. Although it is useful for restoration when an error is modified, it is still uncomfortable. Therefore, it is more suitable for me to turn it off.
Add at the end of the _ vimrc file
Set nobackup
You can.
4, Automatically enable line number
For programmers, the line number is really too important, because in many cases, the error locating in Debugging requires the line number. Input in vim: setnu can enable the row number function, but it is better for people who are used to enabling the row number function every time. Edit the _ vimrc file and add it at the end
Set nu
You can.
5, RunPythonScript keyboard ing
You can press a shortcut key under vim to directly run the current Python script. As shown in the following figure, the f12key is used, and the environment variable has already handled the situation of python.exe. You can modify the specific habits and paths by yourself. Add this line to the _ vimrc file.
Map
In this way, you can press F12 at any time when editing the Python script, and then press the Enter key to execute the current script. There is also a very considerate function during execution, that is, for the console script, it is not directly exited after execution, but to request to press any key before exiting.
6, UseCtagsFunction
This feature is so powerful that we can only talk about it. you can also explore the specific intimate features. Let's talk about installation first. Download a ctags Windows version from the http://ctags.sourceforge.net. Note: The latest version may not have the forwin32 version, so you need to update it to another version.
After downloading the file, put the decompressed ctags.exe file into the vim folder, provided that the vim execution file PATH has been added to the PATH variable.
Click [create] in the gvim tool menu, or enter
:! Ctags-R
In this way, you can create a tags file in the current path, and then you can use the redirection function in vim. The-R option indicates the related symbols in the recursive search subdirectory. The so-called jump is to be able to go to the desired function, type, struct, class and other definitions at any time. For example, when the cursor is at any position, it can be input in normal mode.
: Ta func_name
You can direct the cursor to the func_name function. Of course, other names can also be quickly located using this method. In addition, you can press Ctrl +] when the cursor points to a function name to jump to the definition of this function immediately. After you jump to the defined position, you can press Ctrl + o to quickly return to the original editing position.
The differences between the following ctags and tags need to be clarified. Ctags is a program used to generate the tags file. The tags file is the tag link file of all source files in the current directory. In vim without ctags, a new tags file cannot be generated, but the existing tags file can still be used.
If the tags file is no longer in the current directory, use
: Set tags = filename
.
Create other library filesTagsFile:
In command line mode, enter the Directory of the database file (usually include and src ), run ctags-R -- c ++-kinds = + p -- fields = + iaS -- extra = + q. Then, in the file directory of the library, you can get a file named tags, and set in _ vimrc:
Set tags + = E: \ master2python \ python \ Python-2.6 \ tags
If you only need supertab, rename the generated tags and copy it to your own tags directory, and set it in _ vimrc.
7Enable code folding
Download the python_fold plug-in. decompress the package to the python_fold.vim file and put it in the plugin directory. You can fold Python code. When you open the Python script again, you will find that all the code has been folded, and the number of lines in the collapsed part is also displayed. Press zo on the collapsed line to open the collapse, and press zc to collapse the code. (By gashero)
After code folding, do you feel that vim has become a quite modern editor. Haha, there will be some highlights later.
8, EnableTaglistFunction
The taglist function enables a list on the left side of the vim window to provide all the symbols in the tags file generated by ctags. At this time in? In the taglist window, locate the symbol to jump to, position the cursor, and press enter to locate the cursor to the code position in the right window. Easy to use. Make sure that the tags file already exists. In addition, for switching between two windows, I am used to pressing Ctrl + w twice.
Taglist is a taglist. vim file to be downloaded, can you go to the http://www.vim.org/scripts/script.php? Script_id = 1, 273
.
Put the file extracted from the taglist under the plug-in path of the vim installation path. By default, taglist is disabled. The difference is that python_fold is enabled by default. Manually open, enter in normal mode
: Tlist
In addition, the default taglist method has not been found yet. Which of the following statements can help you?