lua.vim (2529B)
1 " Vim filetype plugin file. 2 3 " Language: Lua 4 " Maintainer: Doug Kearns <dougkearns@gmail.com> 5 " Previous Maintainer: Max Ischenko <mfi@ukr.net> 6 " Contributor: Dorai Sitaram <ds26@gte.com> 7 " C.D. MacEachern <craig.daniel.maceachern@gmail.com> 8 " Tyler Miller <tmillr@proton.me> 9 " Phạm Bình An <phambinhanctb2004@gmail.com> 10 " @konfekt 11 " Last Change: 2025 Apr 04 12 " 2025 May 06 by Vim Project update 'path' setting #17267 13 14 if exists("b:did_ftplugin") 15 finish 16 endif 17 let b:did_ftplugin = 1 18 19 " keep in sync with syntax/lua.vim 20 if !exists("lua_version") 21 " Default is lua 5.3 22 let lua_version = 5 23 let lua_subversion = 3 24 elseif !exists("lua_subversion") 25 " lua_version exists, but lua_subversion doesn't. In this case set it to 0 26 let lua_subversion = 0 27 endif 28 29 let s:cpo_save = &cpo 30 set cpo&vim 31 32 setlocal comments=:---,:-- 33 setlocal commentstring=--\ %s 34 setlocal formatoptions-=t formatoptions+=croql 35 setlocal path-=. " Lua doesn't support importing module in path related to current file like JS 36 37 let &l:define = '\<function\|\<local\%(\s\+function\)\=' 38 39 let &l:include = '\<\%(\%(do\|load\)file\|require\)\s*(' 40 setlocal includeexpr=s:LuaInclude(v:fname) 41 setlocal suffixesadd=.lua 42 43 let b:undo_ftplugin = "setl cms< com< def< fo< inc< inex< sua< pa<" 44 45 if exists("loaded_matchit") && !exists("b:match_words") 46 let b:match_ignorecase = 0 47 let b:match_words = 48 \ '\<\%(do\|function\|if\)\>:' .. 49 \ '\<\%(return\|else\|elseif\)\>:' .. 50 \ '\<end\>,' .. 51 \ '\<repeat\>:\<until\>,' .. 52 \ '\%(--\)\=\[\(=*\)\[:]\1]' 53 let b:undo_ftplugin ..= " | unlet! b:match_words b:match_ignorecase" 54 endif 55 56 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") 57 let b:browsefilter = "Lua Source Files (*.lua)\t*.lua\n" 58 if has("win32") 59 let b:browsefilter ..= "All Files (*.*)\t*\n" 60 else 61 let b:browsefilter ..= "All Files (*)\t*\n" 62 endif 63 let b:undo_ftplugin ..= " | unlet! b:browsefilter" 64 endif 65 66 " The rest of the file needs to be :sourced only once per Vim session 67 if exists("s:loaded_lua") || &cp 68 let &cpo = s:cpo_save 69 unlet s:cpo_save 70 finish 71 endif 72 let s:loaded_lua = 1 73 74 function s:LuaInclude(fname) abort 75 let lua_ver = str2float(printf("%d.%02d", g:lua_version, g:lua_subversion)) 76 let fname = tr(a:fname, '.', '/') 77 let paths = lua_ver >= 5.03 ? [fname .. ".lua", fname .. "/init.lua"] : [fname .. ".lua"] 78 for path in paths 79 if filereadable(path) 80 return path 81 endif 82 endfor 83 return fname 84 endfunction 85 86 let &cpo = s:cpo_save 87 unlet s:cpo_save 88 89 " vim: nowrap sw=2 sts=2 ts=8 noet: