Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tame Vim keyword (not omni) completion for Perl files?

[Update 06/2013: As user doubleDown observed, I have the terminology wrong: The handy C-p and C-n keystrokes are not omni completion (omnicompletion), but keyword completion. I think the Vim terminology is somewhat unfortunate here: omni is Latin for every, whereas keyword seems to be a more restricted selection. The way C-p and C-n work by default is to complete every word of prose, not just keywords. Which made me think that they must be omni completion, not just keyword completion.]

Well ... :-) ... just typing in the title of my question, a highly effective answer turned up in the catalogue of questions with similiar titles. (Which just goes to show how good this website is!) I'm going to ask the question anyway - maybe someone's got an even more fulfilling answer in store ... So here goes:

Vim keyword omnicompletion (by default bound to C-p and C-n in edit mode) is a poor man's Intellisense, that in my experience is almost as good. It searches the buffers for matching strings.

However, some filetype scripts go over the top by having keyword omnicompletion perform a recursive search of included files. (Update: Searching included files is actually the default, as can be seen by :help 'complete' as of Vim 7.3; it's just that with some filetypes, lots of stuff gets included, which results in slowness, possibly aggravated by suboptimal algorithms.) So for a Perl script, it'll start searching the list of modules. Recursively. That can quickly degenerate into some serious scanning, you know, disk I/O and all that ugly stuff.

As a result, I rather refrain from using the feature, because I lose the time and convenience I'm gaining by having to interrupt the search using C-c, which leaves some random string in the output that I then have to delete.

So the best solution so far is simply to disable use of included files in default completion by saying:

:set complete-=i    # remedy
:help 'complete'    # documentation

Anything to add to that?

like image 828
Lumi Avatar asked Jul 04 '11 09:07

Lumi


2 Answers

If you want to be a little more surgical, you can use:

autocmd FileType perl set complete-=i

so that you are just impacting the behaviour for perl code.

like image 94
afourney Avatar answered Oct 11 '22 04:10

afourney


You should use perlomni writen by c9s.

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

http://www.vim.org/scripts/script.php?script_id=2852

You can see video how to use.

http://www.youtube.com/watch?v=hZ7871WcIv0

for easy way, to complete method, type something and "->", then .

#!perl
use strict;
use warnings;
use DateTime;

my $dt = DateTime->new;

$dt->ye # type <c-x><c-o>, you'll get $dt->year
like image 34
mattn Avatar answered Oct 11 '22 06:10

mattn