如何使用vim编辑器打造pythonIDE,实现代码自动补全,自动缩进等

1、vim—自动缩进(编写Python脚本)

使用vim编写python文件的时候不能按照正常的编辑器进行缩进,需要修改vimrc文件。Ubuntu系统下vimrc文件的位置:

$ cd /etc/vim/

$ sudo vim vimrc

添加如下到vimrc文件的最下方:

set filetype=python
au BufNewFile,BufRead *.py,*.pyw setf python
set autoindent " same level indent
set smartindent " next level indent
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4

然后便实现了自动缩进功能。

2、实现智能提示及代码自动补全功能

可以实现下面python代码的自动补全:

1.简单python关键词补全
2.python 函数补全带括号
3.python 模块补全
4.python 模块内函数,变量补全
5.from module import sub-module 补全

首先我们需要安装一个插件:pydiction
下面的两个链接是安装包
http://vim.sourceforge.net/scripts/script.php?script_id=850

https://github.com/rkulla/pydiction

也可以直接在xshell中使用命令安装:

wget https://github.com/rkulla/pydiction/archive/master.zip
unzip -q master
mv pydiction-master pydiction
mkdir -p ~/.vim/tools/pydiction
cp -r pydiction/after ~/.vim
cp pydiction/complete-dict ~/.vim/tools/pydiction
下面是安装好的文件的目录:
# tree ~/.vim
/root/.vim
├── after
│   └── ftplugin
│       └── python_pydiction.vim
└── tools
    └── pydiction
        └── complete-dict

插件安装好了之后我们需要进行配置:
创建一个 ~/.vimrc文件 touch ~/.vimrc
连接文件 cat ~/.vimrc
添加如下代码到vimrc文件中 vim vimrc

filetype plugin on
let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'
let g:pydiction_menu_height = 3

现在打开vim编辑器就可以实现如上功能了
使用Tab键就可以联想代码了。
在这里插入图片描述
在这里插入图片描述

发布了71 篇原创文章 · 获赞 25 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_40985788/article/details/104372180