Skip to content

wsdjeg/altf.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

altf.nvim

altf.nvim is a project alternate file manager for neovim.

GitHub License GitHub Issues or Pull Requests GitHub commit activity GitHub Release

Intro

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.

Installation

require("plug").add({
	{
		"wsdjeg/altf.nvim",
	},
})

Custom alternate file

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"
  }
}

Using toml alternate configuration

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"

Using buffer scoped variable

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,
})

Credits

Self-Promotion

Like this plugin? Star the repository on GitHub.

Love this plugin? Follow me on GitHub.

License

This project is licensed under the GPL-3.0 License.

About

alternate file manager for neovim

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors 2

  •  
  •  

Languages