sponsor Vim development Vim logo Vim Book Ad

lua_omni : omni completion for Lua plus few extras

 script karma  Rating 37/14, Downloaded by 2182  Comments, bugs, improvements  Vim wiki

created by
Radek Kowalski
 
script type
ftplugin
 
description
This is my omni completion plugin for Lua. It works by scanning _G and parsing
Vim buffers. It's also possible to specify external text files with Lua names
paths (delimited with new line). It's a very useful feature when a module can
not be loaded or doesn't have iterable table exposed.

Nested tables are supported so you can type:
:lua foobar = {numbers = {one = 1, two = 2, three = 3}}

Then typing CTRL-X CTRL-O list of possible matches will open:
  foobar.numbers.one
  foobar.numbers.two
  foobar.numbers.three

Actually you can use globbing "*" and "?" characters to speed up typing like:
  f*tw CTRL-X CTRL-O
will output immediately:
  foobar.numbers.two

Single word can be used as well:
three CTRL-X CTRL-O
will give:
  foobar.numbers.three
Or even just "thr" will work too.

Another way use completion is without any asterisks like:
p.l.m CTRL-X CTRL-O
to get:
  package.loaded.math


That is the new way of doing omni from this version. I've found it to be quicker
and more convenient than multiple hitting CTR-X CTRL-O.
Local variables completion works as before.


Some other functions are supported like listing defined Lua functions in
current buffer.
There are common Lua abbreviation defined in lua_omni.vim too.

                                                                      
Mappings:

CTRL-X CTRL-O
    Calling the omni completion function.

<Leader>fl  or  <Plug>PrintFunctionList
    Prints list of defined Lua functions in current buffer. They are listed in
    ascending line numbers order. Luadoc titles (if defined) are showed too.
                                                                      
<Leader>lf  or  <Plug>WriteAndLuaFile
    Just a shortcut to call:
        :w
:luafile %

<Leader>sli or  <Plug>SetLuaIabbrevs
    Sets few common and useful insert mode abbreviations.

<Leader>cli or  <Plug>ClearLuaIabbrevs
    Clear any insert mode abbreviations set by previous shortcut.

                                                                      
                        *lua_omni-settings*

From 0.16 version there is support for external files with completion paths.
They can be specified via shell LUA_OMNI variable. Each file path should be
delimited by comma or semicolon. Additionally the same can done using Vim
b:lua_omni and g:lua_omni variables. The b: if exists will override g: however
shell LUA_OMNI will be read and used in all cases.

Format of completions files is very simple. Each line contains single Lua
path like:

foomodule.barPart
foomodule.barPart.spam
foomodule.barPart.spam.not
foomodule.barPart.spam.twice
foomodule.barPart.spam.multiply
foomodule.__inner
foomodule.__inner.foo
math2mod
math2mod.exp
math2mod.div
...
(and so on)

Order of lines is meaningless as results are sorted anyway.
You may try lapg.lua script to generate such completion list automatically.


From 0.17 version there is folding using foldexpr function. To enable it just
set foldenable option. It has configurable variables: g:lua_inner_folds and
b:lua_inner_folds. When set to 1 folding is nested. When not existent, or set
to other value than 1, folds will have one level only.  Of course the b:
version will override the g:.

To regenerate folds use the zx or zX normal commands.

Though folding function try not to fold malformed blocks it depends on correct
order of opening/closing statements.
 
install details
Just extract and copy files from lua_omni.zip into local .vim/ftplugin and
.vim/doc directories. Then execute in Vim:
:helptags ~/.vim/doc

Alternatively you may download it from github at:
git@github.com:rkowal/Lua-Omni-Vim-Completion.git

To get a help type:
:help lua_omni

Beware! Vim 7.3 is needed with enabled Lua support.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
lua_omni_v0.17.zip 0.17 2011-05-20 7.3 Radek Kowalski + added folding for Lua code by foldexpr function
lua_omni_v0.165.zip 0.165 2011-05-01 7.3 Radek Kowalski + variables defined in for loops should complete now
+ changed find_assigments function
+ added the lapg.lua script for auto generating Lua completion list names
  from documentation (html or text files)
+ changed licence to MIT
lua_omni_v0.163.zip 0.163 2011-04-27 7.3 Radek Kowalski + new variable completion now can see variables names in function
  definitions too
lua_omni_v0.162.zip 0.162 2011-04-26 7.3 Radek Kowalski + fixed bug in print_function_list when a buffer doesn't have any
  functions
+ added better variable assignments completion
lua_omni_v0.16.zip 0.16 2011-04-26 7.3 Radek Kowalski + user can specify files with Lua completions using shell LUA_OMNI and Vim
  b:lua_omni, g:lua_omni variables
  (useful when _G context can not have everything loaded)
lua_omni_v0.151.zip 0.151 2011-04-20 7.3 Radek Kowalski + fixed small (thought irritating) bug in completion_findstart function
lua_omni_rev0.15.zip 0.15 2011-04-05 7.3 Radek Kowalski + More convenient completion where single words or asterisk less shortcuts
  will work too.
lua_omni_rev0.141.zip 0.141 2011-03-29 7.3 Radek Kowalski + Minor fix in completing function where was a chance to concat table with
  string.
lua_omni_rev0.14.zip 0.14 2011-03-28 7.3 Radek Kowalski + Fixed bug in new completing function so root level names in _G table are
  actually showed.
+ Fixed previously introduced bugs in Vim mappings.
lua_omni_rev0.13.zip 0.13 2011-03-25 7.3 Radek Kowalski     + Changed scanning of _G table to more elaborate way. Now a "globbing" "*"
  and "?" characters may be used when typing.
    + Few additions to abbreviations.
lua_omni_012.zip 0.12 2010-11-29 7.3 Radek Kowalski + improved Lua search_assignments1 function to search variable names in "for in" and function statements
lua_omni_011.zip 0.11 2010-11-20 7.3 Radek Kowalski ---------------------------------------------------------------------------------------
  RELEASE NOTES FOR VERSION 0.11
---------------------------------------------------------------------------------------
+ fixed error in abbreviations
+ added abbreviation for string.len
+ expanded omnifunc functionality to scan local function variables (works
  for the most part)
lua_omni.zip 0.1 2010-11-17 7.3 Radek Kowalski Initial upload
ip used for rating: 3.149.243.32

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github