如何在配置vim的(Python)代码自动补全功能

Description
===========
Pydiction allows you to Tab-complete Python code in Vim, including keywords, the standard library, and third-party modules. 

It consists of three main files:
   
    python_pydiction.vim -- This is an ftplugin you put in your non-system ftplugin directory (i.e., ~/.vim/after/ftplugin/, on Unix or C:/vim/vimfiles/ftplugin/, on Windows)
    complete-dict -- This is a vim dictionary file that consists of Python keywords and modules. This is what python_pydiction.vim looks at to know which things are completable.
    pydiction.py -- (Not required) This is a Python script that was used to generate complete-dict. You can optionally run this script to add more modules to complete-dict.


Install Details
===============
Unix/Linux: Put python_pydiction.vim in ~/.vim/after/ftplugin/   (If this directory doesn't already exist, create it. Vim will know to look there automatically.)
Windows: Put python_pydiction.vim in C:/vim/vimfiles/ftplugin  (Assuming you installed Vim to C:/vim/).

You may install the other files (complete-dict and pydiction.py) anywhere you want. For this example, we'll assume you put them in "C:/vim/vimfiles/ftplugin/pydiction/" (Do not put any file but python_pydiction.vim in the ftplugin/ directory, only .vim files should go there.)

In your vimrc file, first add the following line to enable filetype plugins:
 
    filetype plugin on

then make sure you set "g:pydiction_location" to the full path of where you installed complete-dict, i.e.:
   
    let g:pydiction_location = 'C:/vim/vimfiles/ftplugin/pydiction/complete-dict'

You can optionally set the height of the completion menu by setting "g:pydiction_menu_height" in your vimrc. For example:
   
    let g:pydiction_menu_height = 20

The default menu height is 15.

 

1:将python_pydiction.vim文件拷贝到d:/vim/vimfiles/ftplugin中

2:将complete-dict拷贝到d:/vim/vimfiles/ftplugin/pydiction/complete-dict中

3:编辑.vimrc 文件,增加如下:

"pydiction 1.2 python auto complete
filetype plugin on
let g:pydiction_location = 'd:/vim/vimfiles/ftplugin/pydiction/complete-dict'
"defalut g:pydiction_menu_height == 15
"let g:pydiction_menu_height = 20

Python代码自动补全可以通过多种方式实现。在使用vim编辑器时,可以通过以下步骤实现Tab键自动补全:首先,确保你已经安装了vim插件YouCompleteMe。然后,设置YouCompleteMe的配置文件,使其支持Python代码自动补全。接下来,在vim编辑器中打开Python文件,当你输入代码时,按下Tab键即可进行自动补全。 此外,在Python的交互模式下,也可以实现Python代码自动补全。在Python交互模式下,当输入部分代码时,按下Tab键会自动补全代码中的关键词、函数和变量。这种自动补全功能可以帮助提高代码编写的效率。 另外,如果你在使用IDLE编写代码时遇到延时弹出代码补全或无法出现补全的现象,可以通过更改代码补全的配置文件来解决。在Python的安装目录下的Python\Python37\Lib\idlelib目录下,找到config-extensions.def文件。打开该文件,你可以找到AutoComplete字段,其中包含了自动补全的相关配置信息。你可以修改popupwait的值来调整延时弹出补全的时间,以适应你的需求。 综上所述,Python代码自动补全可以通过不同的编辑器或工具实现,如vim编辑器和Python交互模式。同时,你还可以根据需要调整配置文件来优化自动补全的表现。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Python自动补全](https://blog.csdn.net/weixin_34220963/article/details/85708382)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [【Python】之配置自带的 IDLE](https://blog.csdn.net/aiwangtingyun/article/details/88319012)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值