vim python补全插件

本文介绍了如何使用pydiction这个较简单的vim Python补全插件,它通过创建一个complete-dict文件来实现函数补全。虽然比youcompleteme落后,但安装简便,不需复杂配置。pydiction不支持Python3,但通过修改源码可使其兼容。文章提供了解析和修改源码的示例,以实现对Python3的支持。
摘要由CSDN通过智能技术生成

pydiction是一个比较老的python补全插件,相比于youcompleteme来说确实落后了不少,但是安装更加简单快捷,没有很复杂的配置,就想拿来代替youcompleteme,查看了一下代码,发现只支持python2(插件太老了,python3之后就没有什么更新)

这个插件不是读取python3的包,而是读取一个文件complete-dict,这个文件可以手工编辑,需要的函数添加进去,在vim当中使用tab键就能自动提示和补齐,自定义的元素更多,原作者当时写了一个.py的脚本用于手工添加,但是只支持python2的语法

插件的安装网上其他开发者的教程很全,这里就不赘述了,我修改了这个脚本里面python2的写法,让他兼容python3源码如下

#!/usr/bin/env python
"""
pydiction.py 1.2.3 by Ryan Kulla (rkulla AT gmail DOT com).
License: BSD.
Description: Creates a Vim dictionary of Python module attributes for Vim's
             completion feature.  The created dictionary file is used by
             the Vim ftplugin "python_pydiction.vim".
Usage: pydiction.py <module> [<module> ...] [-v]
Example: The following will append all the "time" and "math" modules'
         attributes to a file, in the current directory, called "pydiction",
         with and without the "time." and "math." prefix:
             $ python pydiction.py time math
         To output only to stdout and not append to file, use -v:
             $ python pydiction.py -v time math
"""


__author__ = "Ryan Kulla (rkulla AT gmail DOT com)"
__version__ = "1.2.3"
__copyright__ = "Copyright (c) 2003-2014 Ryan Kulla"


import os
import sys
import types
import shutil


# Path/filename of the vim dictionary file to write to:
PYDICTION_DICT = r'complete-dict'
# Path/filename of the vim dictionary backup file:
PYDICTION_DICT_BACKUP = r'complete-dict.last'

# Sentintal to test if we should only output to stdout:
STDOUT_ONLY = False


def get_submodules(module_name, submodules):
    """Build a list of all the submodules of modules."""

    # Try to import a given module, so we can dir() it:
    try:
        imported_module = my_import(module_name)
    except ImportError:
        return submodules

    mod_attrs = dir(imported_module)

    for mod_attr in mod_attrs:
        try:
            if isinstance(getattr(imported_module, mod_attr), types.ModuleType):
                submodules.append(module_name + '.' + mod_attr)
        except AttributeError as e:
            print (e)

    return submodules

def get_format(imported_m

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值