SpaceVim

A modular Vim/Neovim configuration


Home | About | Quick start guide | Documentation | Development | Community | Sponsors | 中文


Blogs » Use Vim as a Lua IDE

This is a general guide for using SpaceVim as a Lua IDE, including layer configuration and usage. Each of the following sections will be covered:

Enable language layer

To add Lua language support in SpaceVim, you need to enable the lang#lua layer. Press SPC f v d to open SpaceVim configuration file, and add following configuration:

[[layers]]
  name = "lang#lua"

for more info, you can read the lang#lua layer documentation.

Code completion

lang#lua layer will load the vim-lua plugin automatically, unless overriden in your init.toml. The completion menu will be opened as you type.

lua

Syntax linting

The checkers layer is enabled by default. This layer provides asynchronous syntax linting via neomake. It will run luac asynchronously.

luac

Jump to test file

SpaceVim use built-in plugin to manager the files in a project, you can add a .projections.json to the root of your project with following content:

{
  "src/*.lua": {"alternate": "test/{}.lua"},
  "test/*.lua": {"alternate": "src/{}.lua"}
}

with this configuration, you can jump between the source code and test file via command :A

running code

To run current script, you can press SPC l r, and a split windows will be openen, the output of the script will be shown in this windows. It is running asynchronously, and will not block your vim.

luarunner

Code formatting

The format layer is also enabled by default, with this layer you can use key binding SPC b f to format current buffer. Before using this feature, please install luaformatter or stylua.

luarocks install formatter

Install stylua in windows:

scoop install stylua

REPL support

Start a lua -i inferior REPL process with SPC l s i. After the REPL process being started, you can send code to inferior process, all key bindings prefix with SPC l s, including sending line, sending selection or even send whole buffer.

luarepl

Powered by Jekyll