Ldoc is a LUA document generation tool, detailed in the Ldoc GitHub homepage, but in vim the handwritten notes are more complex, and then read the Vim script, wrote a vim plugin, For automatic generation of module annotations, type annotations and function annotations for easy development. Name this file Ldoc.vim in the ~/.vim/plugin directoryuse: Move the cursor to the current line where you want the comment, then in command mode, enter LDOCM,LDOCT,LDOCF for module comments, type comments and function comments, and map self-mapping shortcut keys
- reference documentation for VIM script http://vimdoc.sourceforge.net/htmldoc/usr_41.html
- Introduction to Ldoc http://keplerproject.github.io/luadoc/manual.html
"Http://vimdoc.sourceforge.net/htmldoc/usr_41.html" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " "" "function! S:warnmsg (msg) Echohl warningmsgecho a:msgechohl noneendfunction "plugin repetitive load conflict detection if exists (" LOADED_LDOC_DDC ") call S: Warnmsg ("Ldoc already loaded!") Finishendiflet LOADED_LDOC_DDC = 1 "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " Ldoc_startbegincommenttag ") Let G:ldoc_startbegincommenttag ="----------------------------------------"Endifif! Exists ("G:ldoc_startendcommenttag") Let G:ldoc_startendcommenttag = "----------------------------------------" Endifif!exists ("G:ldoc_startnotecommenttag") Let G:ldoc_startnotecommenttag = "---" Endifif!exists ("G:ldoc_ Startflagcommenttag ") Let G:ldoc_startflagcommenttag ="--"endif" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "If!exists (" G:ldoc_flagauthor ") Let G:ldoc_flagauthor =" @author "Endifif!exists (" G:ldoc_flagtype ") Let G:ldoc_flagtype = "@type" Endifif!exists ("G:ldoc_flAgparam ") Let G:ldoc_flagparam =" @param "Endifif!exists (" G:ldoc_flagreturn ") Let G:ldoc_flagreturn =" @return "endif" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Write function "details refer to the APPEND function, parameter 2 can be passed directly to the list" "" "" "" "" "" "" "" "" "" "" "" "" function! S:writetonextline (str) Call append ("."), A:str) endfunctionfunction! S:writetoprevline (str) Call append (".") -1, A:str) endfunction "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" <sid>ldoc_modulecomment () If!exists ("G:ldoc_authorname") Let G:ldoc_authorname = input ("Enter author name:") endiflet L: Moduledesc = input ("Input module simple description (can enter directly, fill in later):") mark Llet l:writetext = [G:ldoc_startbegincommenttag]let l:str = g:ldoc_ Startnotecommenttagif (strlen (l:moduledesc) = = 0) Mark Melselet l:str = l:str. L:moduledescendifcall Add (L:writetext, L:STR) call Add (L:writetext, G:ldoc_startflagcommenttag. G:ldoc_flagauthor. G: Ldoc_authorname) call Add (L:writetext, G:ldoc_startendcommenttag) call S:writetoprevline (L:writetext) if (strlen (l: MODULEDESC) = = 0) exec "normal ' m" ElseexEC "Normal" L "endifendfunction" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " <sid>ldoc_typecomment () Let l:curlinestr = Getline (".") Let l:typenamelist = Matchlist (l:curlinestr, ' local[\t]\+\ ([a-za-z0-9_]\+\] [\t]\+ ') if (Len (l:typenamelist) < 2) Call S:warnmsg ("Get type failed, call [email protected]") returnendiflet l:typename = L:typenamelist[1]let L:typedesc = Input ("Enter a simple description of the type (can be entered directly, fill in later):") mark Llet l:writetext = []let l:str = G:ldoc_startnotecommenttagif (strlen (L:TYPEDESC) = = 0) Mark Melselet l:str = l:str. L:typedescendifcall Add (L:writetext, L:STR) call Add (L:writetext, G:ldoc_startflagcommenttag. G:ldoc_flagtype. L: TypeName) Call S:writetoprevline (L:writetext) if (strlen (l:typedesc) = = 0) exec "normal ' m" elseexec "normal ' L" Endifendfunction "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "function! <sid>ldoc_functioncomment () Let l:curlinestr = Getline (".") Let l:paramlist = Matchlist (l:curlinestr, ' function[\t]\+\ ([A-Za-z0-9_.:]\+\) [\t]* (\ ([A-za-z0-9_, \t\.] *\)) if (Len (l:paramlist) >= 2) Elselet l:paramlist = matchlist (L:curlinestr, ' \ ([a-za-z0-9_]\+\] [\t]*=[\t]* function[\t]* (\ ([A-za-z0-9_, \t\.] *\)) if (Len (l:paramlist) < 2) call s:warnmsg ("Get function failed, call [email protected]") Returnendifendiflet L:funcname = L:paramlist[1]if (len (l:paramlist) > 3) Let l:paramlist = Split (l:paramlist[2], ' [\t]*,[\t]* ') Let l:paramlist2 = []fo R L:ele in L:paramlistcall Add (l:paramlist2, substitute (L:ele, ' [\t]+ ', "", "")) Endforendifmark llet L:funcdesc = input (" Enter function [". L:funcname. "] A simple description (you can enter directly, fill in later):" Let L:writetext = []let l:str = G:ldoc_startnotecommenttagif (strlen (l:funcdesc) = = 0) mark Melselet l:str = l:str. L:funcdescendifcall Add (L:writetext, l:str) for l:ele in L:paramlist2let l:str = G:ldoc_startflagcommenttag. G:ldoc_flagparam. L:elelet L:paramdesc = input ("input parameter ["). L:ele. A simple description of "] if (strlen (L:PARAMDESC) > 0) Let l:str = L:str." \ t ". L:paramdescendifcall Add (L:writetext, L:STR) endforcAll S:writetoprevline (L:writetext) if (strlen (l:funcdesc) = = 0) exec "normal ' m" elseexec "normal ' L" endifendfunction "" " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" command! -nargs=0 ldocm:call <sid>ldoc_modulecomment () command! -nargs=0 ldoct:call <sid>ldoc_typecomment () command! -nargs=0 Ldocf:call <sid>ldoc_functioncomment ()
Self-writing VIM plugin Ldoc.vim, providing intelligent LUA Annotation code completion