Last Modified: 2023-07-03 00:00:00
vim-lua-format.nvim is forked from vim-lua-format, and rewrited wth lua.
Add default lua-format config file:".lua_format.default"(when not found ".lua-format" then using this default config file).
Lua vim formatter supported by LuaFormatter(lua-format).
Use lazy.nvim
, add this to "plugin.lua"
{
"pchaos/vim-lua-formatter.nvim",
branch="main",
ft={ "lua"}
},
And it's done!
Then press <C-K>
or simply save some *.lua
file to format the Lua code automatically.
NOTE if you need to use the LuaFormat()
function directly from command mode, you should call it explicitly as :lua LuaFormat()
Reformats your Lua source code with default config file : ".lua-format.default".
.lua-format
: Specifies the style config file. Style Options
The .lua-format
file must be in the source or parent directory. If there is no configuration file the default settings are used.
- You may have an error that claims unknown
-i
or-si
options. This is happening because some versions oflua-formatter
uses different flags.
So if you get any error about unknown flag, just change it to the correct flag in flags string variable at lua_format_format()
function.
- No line breaks after closing block comment In files with block comments, something like this:
--[[
Bigger comment
--]]
local var
becomes this after format with lua-format
default settings.
--[[
Bigger comment
--]] local var
This was seen with the version included in current formatter:lua-format
(version 1.3.6)
A workaround for this issue is ending a multiline comment with --]] --
--[[
Bigger comment
--]] --
local var