altf.nvim is a project alternate file manager for neovim.
altf.nvim is a lightweight project alternate files manager for neovim, it helps you quickly switch between alternate files. Such as source and docs, source and test files, implementation and header pairs, or related modules in your project.
With altf.nvim, you can jump between alternate files with a single command :A.
- use nvim-plug
require("plug").add({
{
"wsdjeg/altf.nvim",
},
})To manage the alternate file of the project, you need to create a .project_alt.json file
in the root of your project. Then you can use the command :A to jump to the alternate file of
current file. You can also specific the type of alternate file, for example :A doc.
With a bang :A!, SpaceVim will parse the configuration file additionally. If no type is specified,
the default type alternate will be used.
here is an example of .project_alt.json:
{
"autoload/SpaceVim/layers/lang/*.vim": {
"doc": "docs/layers/lang/{}.md",
"test": "test/layer/lang/{}.vader"
}
}require('altf').set_config_name(vim.fn.getcwd(), '.project_alt.toml')Instead of using json file, the alternate file manager also support .project_alt.toml file, for example:
Note: if you want to use toml file, you need to install wsdjeg/toml.nvim
["autoload/SpaceVim/layers/lang/*.vim"]
# You can use comments in toml file.
doc = "docs/layers/lang/{}.md"
test = "test/layer/lang/{}.vader"If you do not want to use configuration file,
or want to override the default altf configuration, setup b:alternate_file_config for the buffer.
for example:
local augroup = vim.api.nvim_create_augroup("altf-custom", { clear = true })
vim.api.nvim_create_autocmd({ "BufNewFile", "BufEnter" }, {
pattern = { "*.c" },
group = augroup,
callback = function(ev)
vim.api.nvim_buf_set_var(ev.buf, "alternate_file_config", {
["src/*.c"] = {
doc = "docs/{}.md",
alternate = "include/{}.h",
},
})
end,
})
vim.api.nvim_create_autocmd({ "BufNewFile", "BufEnter" }, {
pattern = { "*.h" },
group = augroup,
callback = function(ev)
vim.api.nvim_buf_set_var(ev.buf, "alternate_file_config", {
["include/*.h"] = {
alternate = "src/{}.c",
},
})
end,
})Like this plugin? Star the repository on GitHub.
Love this plugin? Follow me on GitHub.
This project is licensed under the GPL-3.0 License.