Skip to content

Instantly share code, notes, and snippets.

@xebecnan
Created May 21, 2023 03:20
Show Gist options
  • Save xebecnan/d4cbf9f5e3aa0101c7db7cda7d8f7d75 to your computer and use it in GitHub Desktop.
Save xebecnan/d4cbf9f5e3aa0101c7db7cda7d8f7d75 to your computer and use it in GitHub Desktop.
" 清理 Lua 文件头多余的 local 赋值语句 TidyLuaHeadStatements {
fun! IsLuaLocalAssignStatement()
return getline(".") =~ '^local\s\+\S\+\s*='
endfun
fun! IsNecessaryLuaAssignment()
let v1 = line('.')
silent! exe "norm! #"
let v2 = line('.')
silent! exe "norm! N"
return v1 != v2
endfun
fun! TidyLuaHeadStatements()
if getline('.') !~ '^\s*$'
if !IsLuaLocalAssignStatement()
echo "not lua local assignment statement"
return
endif
exec "norm! 0w"
if !IsNecessaryLuaAssignment()
exec "norm! dd"
endif
endif
if line('.') <= 1
echo "first line reached"
return
endif
exec "norm! k"
call TidyLuaHeadStatements()
endfun
command! TidyLuaHeadStatements call TidyLuaHeadStatements()
" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment