Is there any way to enable code completion for Perl in vim?

荒凉一梦 提交于 2019-12-03 05:40:53

问题


Surprisingly as you get good at vim, you can code even faster than standard IDEs such as Eclipse. But one thing I really miss is code completion, especially for long variable names and functions.

Is there any way to enable code completion for Perl in vim?


回答1:


Ctrl-P (Get Previous Match) and Ctrl-N (Get Next Match) are kind of pseudo code completion. They basically search the file (Backwards for Ctrl-P, Forwards for Ctrl-N) you are editing (and any open buffers, and if you are using TAGS anything in your TAG file) for words that start with what you are typing and add a drop down list. It works surprisingly well for variables and function names, even if it isn't intellisense. Generally I use Ctrl-P as the variable or function I am looking for is usually behind in the code. Also if you keep the same copy of Vim open, it will search the files you have previously opened.




回答2:


Vim 7 supports omni completion.

For example, I have this in my vimrc

autocmd FileType php set omnifunc=phpcomplete#CompletePHP

and then, when I press Ctrl-x Ctrl-o in Insert mode, I get a dropdown list of autocomplete possibilities.

Here's an omnicfunc for perl. No idea how well it works though.




回答3:


Well, Vim's generic completion mechanism is surprisingly good, just using Ctrl-N in insert mode. Also, line completion is very handy, using C-x C-l.

Also check out this vim script for perl.




回答4:


The standard CTRL-N and CTRL-P work even better if you add the following to your ~/.vim/ftplugin/perl.vim file:

set iskeyword+=:

It will then auto-complete module names, etc.




回答5:


The .vimrc clip in one of the other answers is slightly wrong. To turn your tab key into an auto-complete key, use this code:

inoremap <tab> <c-r>=InsertTabWrapper()<cr>

function! InsertTabWrapper()
    let col = col('.') - 1
    if !col || getline('.')[col - 1] !~ '\k'
        return "\<tab>"
    else
        return "\<c-p>"
    endif
endfunction

You can find this, and tons of other vim tricks in this thread at Perlmonks--which links to even more threads with lots more customizations.




回答6:


You should look at the SuperTab plugin: http://www.vim.org/scripts/script.php?script_id=1643 It let's you do completion (either the OmniCompletion or the regular completion) using tab and shift-tab instead of ^N and ^P.




回答7:


https://github.com/c9s/perlomni.vim




回答8:


Ctrl+N

This is explained in the Perl Hacks book, along with how to do Package completion. Highly recommended.



来源:https://stackoverflow.com/questions/54104/is-there-any-way-to-enable-code-completion-for-perl-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!