http://www.perlmonks.org?node_id=621766

For us Vim users, there's now a Perl omnicompletion available here. At first glance, it appears to work reasonably well - it has a few rough edges, but is quite a lot better than the previous situation (which was no omnicompletion at all).

For those who aren't aware of it, Vim 7 added omnicompletion, which is an attempt at an intellisense-style smart completion. As an example, if I have

my $now = DateTime->now;

I can subsequently type

$now->^X^O

(control-X, control-O being the standard Vim omnicomplete shortcut) and get a pop-up menu of the available method calls for $now (add_duration, day, day_abbr, etc).

Replies are listed 'Best First'.
Re: Perl omnicompletion available for Vim 7
by blazar (Canon) on Jun 20, 2007 at 22:57 UTC
    (control-X, control-O being the standard Vim omnicomplete shortcut) and get a pop-up menu of the available method calls for $now (add_duration, day, day_abbr, etc).

    BTW: how does it work? Are completions hardcoded, or is for each module the corresponding documentation read and (tried to be) parsed for available methods?

      The release notes mention that it parses any existing POD as best it can, which tallies with my (limited) experience of it thus far.

      Things I've noticed:

      • my $foo = DateTime::^X^O
        gives me a truncated-enough-to-be-of-no-use pop-up menu of all the DateTime::* modules I have installed. I think it's listing them all, but the names are cut off enough that I can't tell what they are. In fairness, this might be something else to do with my reasonably-heavily-customized Vim setup though.
      • my $parser = DateTime::Format::Pg->new(); $parser->^X^O
        only shows 'clone' as an available method and doesn't show any of the available 'parse_*' or 'format_*' methods in DateTime::Format::Pg
      • my $now = DateTime->now; $now->^X^O
        shows 28 of the available matches. DateTime has, at first glance, quite a few more than that, but I've not yet looked any further into how it's finding the ones it is.

      And yes, I'm doing a fair amount of playing with DateTime at the moment... ;-)

        The release notes mention that it parses any existing POD as best it can, which tallies with my (limited) experience of it thus far.

        Well, it is well known that "nothing but perl can parse Perl" (but PPI tries hard to compensate), and POD is not that easy either: perhaps due to the fact that there's no really standardized way for listing methods or public functions, that I know of. Which brings me back to some discussions I must have heard in Perl 6 development circles amongst @Larrys about the desire/need to provide hooks for easy intercommunication between the interpreter proper and development tools like IDEs and smart editors, but unfortunately I can't find any link at the moment. Anyway, that's good news, let's hope to see the beast alive!

        And yes, I'm doing a fair amount of playing with DateTime at the moment... ;-)

        Really? I would have never said...

Re: Perl omnicompletion available for Vim 7
by wazoox (Prior) on Jun 18, 2007 at 15:49 UTC
    It's somewhat off-topic, but I didn't understand how to enable this feature... I had to tweak the script to get it installed, but how do you use it when done?
Re: Perl omnicompletion available for Vim 7
by zby (Vicar) on Jun 21, 2007 at 15:34 UTC
    Looks cool but when I try ^X^O I keep getting an "'omnifunc' option not set error" (even if I do :set omnifunc). Any idea what I've done wrong?

    The installation creates files with some funny names:

    /usr/share/vim/vimfiles/ftplugin/perl/omniperl.vim\ [\[\[1
    This looks like this is some bug. I've tried to change the line 4 from the vba file from:
    ftplugin/perl/omniperl.pl [[[1
    to
    ftplugin/perl/omniperl.pl
    But this did not improve the situation at all.

      It should. I simply renamed the extracted files and voila omnicompletion (in some deranged sense of omni) was available. It's almost unusable for me in it's current state - we'll see if I find the time to take a look on how to improve the situation...*sigh*

      regards,
      tomte


      An intellectual is someone whose mind watches itself.
      -- Albert Camus

        Thanks - after renaming all of the extracted files it worked.

      If I had to guess, I'd say that you may not have the feature compiled into Vim. Though, obviously, if omnicompletion works for other languages, I'm talking nonsense ;-)

      Here's the output from ':version' on the machine I'm in front of now if you want to compare with yours. Mine's had both Perl and Vim compiled from source and I'm pretty certain I 'turned everything up to 11' with Vim.

      :version VIM - Vi IMproved 7.1 (2007 May 12, compiled May 14 2007 14:22:44) MacOS X (unix) version Compiled by johno@johns-g5.local Huge version with Carbon GUI. Features included (+) or not (-): +arabic +autocmd -balloon_eval +browse ++builtin_terms +byte_offset +c +indent -clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +cryptv -cscope +cursorshape +dialog_con_gui + +diff +digraphs -dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +folding -footer +fork() -gettext +-hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap +menu +mksession + +modify_fname +mouse -mouseshape +mouse_dec -mouse_gpm -mouse_jsbterm +mouse_netterm +mouse_xterm +multi_byte +multi_lang -mzscheme -netbean +s_intg -osfiletype +path_extra +perl +postscript +printer +profile +python +quickfix +reltime +rightleft +ruby +scrollbind +signs +smarti +ndent -sniff +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjec +ts +title -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writeb +ackup -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" user exrc file: "$HOME/.exrc" system gvimrc file: "$VIM/gvimrc" user gvimrc file: "$HOME/.gvimrc" system menu file: "$VIMRUNTIME/menu.vim" fall-back for $VIM: "/Applications/Vim.app/Contents/Resources/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MAC -fno-co +mmon -fpascal-strings -Wall -Wno-unknown-pragmas -mdynamic-no-pic -pi +p e -I. -Iproto -DMACOS_X_UNIX -no-cpp-precomp -I/Developer/Headers/Flat +Carbon -g -O2 -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing + -I/usr/local/include -I/opt/local/include -I/usr/local/lib/perl5/5.8. +8/darwin-thread-multi-2level/CORE -I/System/Library/Frameworks/Pytho +n .framework/Versions/2.3/include/python2.3 -I/usr/lib/ruby/1.8/powerpc +-darwin8.0 Linking: gcc -L/usr/local/lib -o Vim -framework Carbon -lncurse +s -liconv -L/usr/local/lib -L/opt/local/lib /usr/local/lib/perl5/5 +. 8.8/darwin-thread-multi-2level/auto/DynaLoader/DynaLoader.a -L/usr/loc +al/lib/perl5/5.8.8/darwin-thread-multi-2level/CORE -lperl -lm -lc -fr +a mework Python -lruby -lobjc

      Actually, I've just had grep through my shell history, and these're the configure options I used:

      ./configure --with-features=huge --enable-perlinterp --enable-pythonin +terp --enable-rubyinterp --enable-multibyte

      Hope that helps