简体   繁体   English

无需任何安装即可在Vim中启用python自动完成功能

[英]Enable python autocompletion in Vim without any install

I am coding Python3 in Vim and would like to enable autocompletion. 我在Vim中编写Python3并希望启用自动完成功能。

I must use different computers without internet access. 我必须使用没有互联网接入的不同计算机 Every computer is running Linux with Vim preinstalled. 每台计算机都运行Linux并预装了Vim。

I dont want to have something to install, I just want the simplest way to enable python3 completion (even if it is not the best completion), just something easy to enable from scratch on a new Linux computer. 我不想安装一些东西,我只想要最简单的方法来启用python3完成(即使它不是最好的完成),只需要在新的Linux计算机上从头开始轻松实现。

Many thanks 非常感谢

Unfortunately Vim, by default doesn't do what you want, you are pretty much limited to the Ctrl-P style, which is better than it seems once you get used to it. 不幸的是,Vim默认情况下没有你想做的事情,你几乎只限于Ctrl-P风格,这比你习惯它看起来要好。

However i also often find myself working on machines that are not allowed to access the internet or have other files placed on them and When i find myself in this situation and i am using an unfamiliar language i sometimes use Vim's dictionary completion: http://vim.wikia.com/wiki/VimTip91 然而,我也经常发现自己在不允许访问互联网的机器上工作或者在其上放置其他文件。当我发现自己处于这种情况并且我使用的是一种不熟悉的语言时,我有时会使用Vim的字典完成: http:// vim.wikia.com/wiki/VimTip91

To populate this dictionary i cat / trim / filter the man pages for the language to get a variety of keywords. 为了填充这个字典,我可以使用/修剪/过滤语言的手册页以获得各种关键字。 I ram these into a filetype specific dictionary: au FileType * execute 'setlocal dict+=~/.vim/words/'.&filetype.'.txt' 我把它们变成了一个特定于文件类型的字典: au FileType * execute 'setlocal dict+=~/.vim/words/'.&filetype.'.txt'

Obviously this isn't the greatest solution and it is a bit heavy handed but it does provide a certain degree of "What is that function called" type stuff. 显然这不是最好的解决方案,它有点沉重,但它确实提供了一定程度的“什么是所谓的功能”类型的东西。

默认情况下,插入模式下的Ctrl-P会使用您正在编辑的文件中已存在的所有单词进行自动完成

If you have compiled vim with +python3 , you can try omnifunc. 如果你用+python3编译了vim,你可以试试omnifunc。 Add following to your ~/.vimrc : ~/.vimrc添加以下内容:

au FileType python setl ofu=python3complete#Complete

Then in insert mode, just type Ctrl X + Ctrl O . 然后在插入模式下,只需键入Ctrl X + Ctrl O.

See :help omnifunc . 请参阅:help omnifunc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM