A neovim plugin written in lua which automatically detects the build system of
your current project and sets makeprg
accordingly.
- neovim >= 0.8
Automatically detects your build system based on the first build file found, currently supports:
- CMake (
CMakeLists.txt
) - Make (
Makefile
) - Meson (
meson.build
) - Zig (
build.zig
) - Cargo (
Cargo.toml
) - Setuptools (
setup.py
)
Automatically detects project root based on the presence of a file
- Git, mercurial, svn and a few other version control systems
- A
package.json
file - Failing all else, build.nvim searches recursively downwards for known build system files
Highly customisable, with sensible defaults
- You can configure almost everything.
Install as you would any other plugin.
" Vimscript
Plug "cyuria/build.nvim"
lua << EOF
require('build').setup {
-- put your configuration here
-- or don't, see the config section for
-- available options and defaults
}
EOF
{
"cyuria/build.nvim",
opts = {}
}
-- lua
use {
"cyuria/build.nvim",
config = function()
require('build').setup {
-- put your configuration here
-- or don't, see the config section for
-- available options and defaults
}
end
}
For detailed info, see :help build.nvim
.
To use build.nvim, just run :make
as you would with any Makefile based
build system. Even if you aren't in the project root directory, build.nvim
should automatically find the project root and add extra arguments for you.
I.e. instead of running make
build.nvim will run
make -C /PATH/TO/YOUR/PROJECT/ROOT
when in a makefile based build system.
Some build systems, i.e. meson and cargo, will need an extra argument, such as
:make compile
with meson or :make build
with cargo. This allows you more
control, like running :make test
or :make check
instead.
build.nvim comes with the following options and defaults.
require('build').setup({
-- Set the makeprg variable during the setup call
set_makeprg_immediately = true,
-- A list of autocommand events upon which to update/set the makeprg
-- varaible
update_on_event = { "DirChanged", },
-- A list of files used for detecting the project root. If any one of these
-- files or directories is detected, that directory is selected as the root
-- directory. If none of the files are found, recursively descend the
-- directory tree until one of them is found
root_files = {
".git",
"package.json",
"_darcs",
".hg",
".bzr",
".svn",
},
-- A list of directories to search for which will be set as the build
-- directory for the project
build_dirs = {
"build", "builddir", "bin"
},
-- Custom build system indicators and programs. Can also be used to
-- overwrite existing indicators and/or programs
extra_indicators = {},
extra_programs = {},
-- The path of the JSON file used to store individually set build
-- directories on a case by case basis using the project root directory
build_dirs_file = vim.fn.stdpath('data') .. '/build.nvim/build_directories.json',
})
Please feel free to submit any PRs or issues, especially if they add support for more build systems. It would be great if we could support every build system under the sun.
Some currently unsupported systems which would be nice to support are
- build2
- Maven or Gradle or something java I don't know
- Bazel
- Better support for the different variations of Make (i.e. GNU make vs BSD make vs NMake etc)
- Ninja
Another cool feature I've been thinking about but been too lazy to implement is
adding a default make command for meson/cargo etc, so that you can run :make
and it will default to :make build
or whatever equivalent. If you want to
open a PR for this that would be incredible.