feat: add a bunch of stuff

This commit is contained in:
Youwen Wu 2024-10-10 00:21:39 -07:00
parent d4034aec9c
commit adcd621763
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
12 changed files with 700 additions and 54 deletions

View file

@ -649,6 +649,38 @@
"type": "github" "type": "github"
} }
}, },
"plugins-lsp-progress": {
"flake": false,
"locked": {
"lastModified": 1721008335,
"narHash": "sha256-OafRT5AnxRTOh7MYofRFjti0+pobKQihymZs/kr5w0A=",
"owner": "linrongbin16",
"repo": "lsp-progress.nvim",
"rev": "d5f4d28efe75ce636bfbe271eb45f39689765aab",
"type": "github"
},
"original": {
"owner": "linrongbin16",
"repo": "lsp-progress.nvim",
"type": "github"
}
},
"plugins-typst-preview": {
"flake": false,
"locked": {
"lastModified": 1727642175,
"narHash": "sha256-n0TfcXJLlRXdS6S9dwYHN688IipVSDLVXEqyYs+ROG8=",
"owner": "chomosuke",
"repo": "typst-preview.nvim",
"rev": "0354cc1a7a5174a2e69cdc21c4db9a3ee18bb20a",
"type": "github"
},
"original": {
"owner": "chomosuke",
"repo": "typst-preview.nvim",
"type": "github"
}
},
"poetry2nix": { "poetry2nix": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
@ -750,7 +782,9 @@
"inputs": { "inputs": {
"blink-cmp": "blink-cmp", "blink-cmp": "blink-cmp",
"nixCats": "nixCats", "nixCats": "nixCats",
"nixpkgs": "nixpkgs_4" "nixpkgs": "nixpkgs_4",
"plugins-lsp-progress": "plugins-lsp-progress",
"plugins-typst-preview": "plugins-typst-preview"
} }
}, },
"rust-analyzer-src": { "rust-analyzer-src": {

View file

@ -29,6 +29,16 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
plugins-typst-preview = {
url = "github:chomosuke/typst-preview.nvim";
flake = false;
};
plugins-lsp-progress = {
url = "github:linrongbin16/lsp-progress.nvim";
flake = false;
};
# see :help nixCats.flake.inputs # see :help nixCats.flake.inputs
# If you want your plugin to be loaded by the standard overlay, # If you want your plugin to be loaded by the standard overlay,
# i.e. if it wasnt on nixpkgs, but doesnt have an extra build step. # i.e. if it wasnt on nixpkgs, but doesnt have an extra build step.
@ -132,23 +142,23 @@
# this includes LSPs # this includes LSPs
lspsAndRuntimeDeps = { lspsAndRuntimeDeps = {
general = with pkgs; [ general = with pkgs; [
lua-language-server # essential
ripgrep ripgrep
python312Packages.pylatexenc python312Packages.pylatexenc
fd
# lsps / formatters
lua-language-server
nixd
nixfmt-rfc-style
]; ];
}; };
# plugins that will load at startup # install lz.n and treesitter grammars
startupPlugins = { startupPlugins = {
gitPlugins = with pkgs.neovimPlugins; [ ]; gitPlugins = with pkgs.neovimPlugins; [ ];
general = with pkgs.vimPlugins; [ general = with pkgs.vimPlugins; [
lz-n lz-n
telescope-nvim
markdown-preview-nvim
render-markdown-nvim
which-key-nvim
rose-pine
nvim-web-devicons
(nvim-treesitter.withPlugins ( (nvim-treesitter.withPlugins (
p: p:
(with p; [ (with p; [
@ -165,6 +175,7 @@
toml toml
yaml yaml
markdown markdown
markdown_inline
svelte svelte
css css
html html
@ -176,16 +187,45 @@
]; ];
}; };
# plugins which are installed and will be lazy-loaded by lz.n # plugins which are installed, but not loaded, and will be handled by
# lz.n (not necessarily lazy loaded)
optionalPlugins = { optionalPlugins = {
gitPlugins = with pkgs.neovimPlugins; [ gitPlugins = with pkgs.neovimPlugins; [
inputs.blink-cmp.packages.${pkgs.system}.default inputs.blink-cmp.packages.${pkgs.system}.default
typst-preview
lsp-progress
]; ];
general = with pkgs.vimPlugins; [ general = with pkgs.vimPlugins; [
nvim-autopairs nvim-autopairs
nvim-lspconfig nvim-lspconfig
intellitab-nvim intellitab-nvim
sleuth sleuth
which-key-nvim
telescope-nvim
markdown-preview-nvim
render-markdown-nvim
rose-pine
nvim-web-devicons
oil-nvim
telescope-ui-select-nvim
harpoon2
toggleterm-nvim
trouble-nvim
lualine-nvim
mini-ai
mini-hipatterns
mini-surround
mini-notify
mini-starter
mini-trailspace
cellular-automaton-nvim
indent-blankline-nvim
mini-bufremove
neogit
gitsigns-nvim
diffview-nvim
barbecue-nvim
undotree
]; ];
}; };
@ -222,13 +262,13 @@
# in your lua config via # in your lua config via
# vim.g.python3_host_prog # vim.g.python3_host_prog
# or run from nvim terminal via :!<packagename>-python3 # or run from nvim terminal via :!<packagename>-python3
extraPython3Packages = { # extraPython3Packages = {
test = (_: [ ]); # test = (_: [ ]);
}; # };
# populates $LUA_PATH and $LUA_CPATH # # populates $LUA_PATH and $LUA_CPATH
extraLuaPackages = { # extraLuaPackages = {
test = [ (_: [ ]) ]; # test = [ (_: [ ]) ];
}; # };
}; };
# And then build a package with specific categories from above here: # And then build a package with specific categories from above here:
@ -261,15 +301,9 @@
general = true; general = true;
gitPlugins = true; gitPlugins = true;
customPlugins = true; customPlugins = true;
test = true; bin = {
example = { websocat = "${pkgs.websocat}/bin/websocat";
youCan = "add more than just booleans"; tinymist = "${pkgs.tinymist}/bin/tinymist";
toThisSet = [
"and the contents of this categories set"
"will be accessible to your lua with"
"nixCats('path.to.value')"
"see :help nixCats"
];
}; };
}; };
}; };

View file

@ -1,5 +1,8 @@
require("keymaps")
require("plugins") require("plugins")
require("scripts.autoroot")
vim.opt.relativenumber = true vim.opt.relativenumber = true
vim.opt.number = true vim.opt.number = true
@ -16,4 +19,36 @@ vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
vim.opt.foldmethod = "expr" vim.opt.foldmethod = "expr"
vim.opt.foldenable = false vim.opt.foldenable = false
vim.cmd("colorscheme rose-pine") vim.cmd.colorscheme("rose-pine")
require('nvim-treesitter.configs').setup({
ensure_installed = {},
sync_install = false,
auto_install = false,
modules = {"highlight", "incremental_selection", "indent"},
ignore_install = {},
highlight = { enable = true },
disable = function(_, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
additional_vim_regex_highlighting = false
})
vim.api.nvim_create_autocmd({
"TermOpen",
}, {
group = vim.api.nvim_create_augroup("terminal", {}),
callback = function()
vim.cmd("setlocal nonumber norelativenumber")
end,
})
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank {higroup='Visual', timeout=300}
end,
})

View file

@ -1,2 +1,41 @@
-- Non-exhaustive collection of keymaps. I've decided it's more sane to place -- Non-exhaustive collection of keymaps. I've decided it's more sane to place
-- plugin specific maps in their respective setup scripts -- plugin specific maps in their respective setup scripts
vim.g.mapleader = " "
vim.keymap.set("n", "<leader>", "<nop>")
vim.keymap.set("t", "<C-Esc>", "<C-\\><C-n>")
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "<leader>mr", function ()
vim.cmd.CellularAutomaton("make_it_rain")
end)
vim.keymap.set("n", "<leader>bruh", function ()
vim.cmd.CellularAutomaton("game_of_life")
end)
-- when searching, also center screen and reopen folds
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")
-- The greatest remap of all time -- the primeagen
vim.keymap.set({"n", "v"}, "<leader>d",'"_d', { desc = "same as `d` but send to black hole register"})
vim.keymap.set({"n", "v"}, "<leader>D",'"_D', { desc = "same as `D` but send to black hole register"})
-- The real greatest remap(s) of all time -- me
vim.keymap.set({"n", "v"}, "<leader>y",'"+y', { desc = "yank to clipboard"})
vim.keymap.set({"n", "v"}, "<leader>Y",'"+Y', { desc = "yank rest of line to clipboard"})
vim.keymap.set({"n", "v"}, "<leader>p",'"+p', { desc = "put after cursor from clipboard"})
vim.keymap.set({"n", "v"}, "<leader>P",'"+P', { desc = "put before cursor from clipboard"})
vim.keymap.set("n", "<leader>gg", function ()
vim.cmd.Neogit()
end, { desc = "Open neogit" })
vim.keymap.set("n", "<leader>gc", function ()
vim.cmd.Neogit("kind=floating commit")
end, { desc = "Open neogit commit menu" })
vim.keymap.set("n", "<leader>u", function ()
vim.cmd.UndotreeToggle()
end, {desc = "Toggle undotree"})

View file

@ -1,6 +1,7 @@
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
lspconfig.lua_ls.setup({ lspconfig.lua_ls.setup({
settings = {
Lua = { Lua = {
runtime = { runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
@ -8,7 +9,7 @@ lspconfig.lua_ls.setup({
}, },
diagnostics = { diagnostics = {
-- Get the language server to recognize the `vim` global -- Get the language server to recognize the `vim` global
globals = { "vim" }, globals = { "vim", "nixCats", "MiniBufremove" },
}, },
workspace = { workspace = {
-- Make the server aware of Neovim runtime files -- Make the server aware of Neovim runtime files
@ -19,4 +20,7 @@ lspconfig.lua_ls.setup({
enable = false, enable = false,
}, },
}, },
},
}) })
lspconfig.nixd.setup({})

45
lua/plugins/harpoon.lua Normal file
View file

@ -0,0 +1,45 @@
return {
"harpoon2",
after = function()
local harpoon = require("harpoon")
vim.keymap.set("n", "<leader>a", function()
harpoon:list():add()
end)
vim.keymap.set("n", "<C-h><C-a>", function()
harpoon:list():select(1)
end)
vim.keymap.set("n", "<C-h><C-s>", function()
harpoon:list():select(2)
end)
vim.keymap.set("n", "<C-h><C-d>", function()
harpoon:list():select(3)
end)
vim.keymap.set("n", "<C-h><C-f>", function()
harpoon:list():select(4)
end)
local conf = require("telescope.config").values
local function toggle_telescope(harpoon_files)
local file_paths = {}
for _, item in ipairs(harpoon_files.items) do
table.insert(file_paths, item.value)
end
require("telescope.pickers")
.new({}, {
prompt_title = "Harpoon",
finder = require("telescope.finders").new_table({
results = file_paths,
}),
previewer = conf.file_previewer({}),
sorter = conf.generic_sorter({}),
})
:find()
end
vim.keymap.set("n", "<C-h><C-h>", function()
toggle_telescope(harpoon:list())
end, { desc = "Open harpoon window" })
end,
}

View file

@ -3,10 +3,3 @@ vim.loader.enable()
local pluginSpec = require("plugins.lz-spec") local pluginSpec = require("plugins.lz-spec")
require("lz.n").load(pluginSpec) require("lz.n").load(pluginSpec)
-- require("markview").setup({
-- codeblocks = {
-- icons = "devicons",
-- },
-- filetypes = {"markdown", "quarto", "rmd", "nofile"}
-- })

58
lua/plugins/lualine.lua Normal file
View file

@ -0,0 +1,58 @@
return {
"lualine.nvim",
event = "BufEnter",
after = function()
require("lualine").setup({
options = {
icons_enabled = true,
theme = "auto",
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
disabled_filetypes = {
statusline = { "ministarter" },
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = true,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
},
},
sections = {
lualine_a = { "branch" },
lualine_b = {
function()
return require("lsp-progress").progress()
end,
},
lualine_c = { "progress", "filetype" },
lualine_x = { "encoding", "fileformat" },
lualine_y = { "diff", "diagnostics" },
lualine_z = { "location" },
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { "filename" },
lualine_x = { "location" },
lualine_y = {},
lualine_z = {},
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {},
})
-- listen lsp-progress event and refresh lualine
vim.api.nvim_create_augroup("lualine_augroup", { clear = true })
vim.api.nvim_create_autocmd("User", {
group = "lualine_augroup",
pattern = "LspProgressStatusUpdated",
callback = require("lualine").refresh,
})
end,
}

View file

@ -1,5 +1,64 @@
return { return {
require("plugins.blink-cmp"), require("plugins.blink-cmp"),
require("plugins.telescope"),
require("plugins.oil"),
require("plugins.harpoon"),
require("plugins.lualine"),
{ "lsp-progress",
after = function()
require("lsp-progress").setup({
client_format = function(client_name, spinner, series_messages)
if #series_messages == 0 then
return nil
end
return {
name = client_name,
body = spinner .. " " .. table.concat(series_messages, ", "),
}
end,
format = function(client_messages)
--- @param name string
--- @param msg string?
--- @return string
local function stringify(name, msg)
return msg and string.format("%s %s", name, msg) or name
end
local sign = "󰆧" -- nf-fa-gear \uf013
local lsp_clients = vim.lsp.get_clients()
local messages_map = {}
for _, climsg in ipairs(client_messages) do
messages_map[climsg.name] = climsg.body
end
if #lsp_clients > 0 then
table.sort(lsp_clients, function(a, b)
return a.name < b.name
end)
local builder = {}
for _, cli in ipairs(lsp_clients) do
if
type(cli) == "table"
and type(cli.name) == "string"
and string.len(cli.name) > 0
then
if messages_map[cli.name] then
table.insert(builder, stringify(cli.name, messages_map[cli.name]))
else
table.insert(builder, stringify(cli.name))
end
end
end
if #builder > 0 then
return sign .. " " .. table.concat(builder, ", ")
end
end
return ""
end,
})
end
},
{ "telescope-ui-select.nvim", priority = 70 },
{ {
"nvim-autopairs", "nvim-autopairs",
event = "BufEnter", event = "BufEnter",
@ -14,12 +73,255 @@ return {
require("lsp") require("lsp")
end, end,
}, },
{
"intellitab-nvim",
keys = "tab",
},
{ {
"sleuth", "sleuth",
event = "BufEnter", event = "BufEnter",
}, },
{
"which-key.nvim",
after = function()
require("which-key").setup({
delay = 1000,
})
end,
},
{ "nvim-web-devicons" },
{ "rose-pine" },
{ "render-markdown.nvim" },
{ "markdown-preview.nvim" },
{
"trouble.nvim",
event = "LspAttach",
after = function()
require("trouble").setup()
vim.keymap.set("n", "<leader>xx", function()
vim.cmd("Trouble diagnostics toggle")
end, { desc = "Diagnostics" })
vim.keymap.set("n", "<leader>xX", function()
vim.cmd("Trouble diagnostics toggle filter.buf=0")
end, { desc = "Buffer diagnostics" })
vim.keymap.set("n", "<leader>cs", function()
vim.cmd("Trouble symbols toggle")
end, { desc = "Symbols" })
vim.keymap.set("n", "<leader>cl", function()
vim.cmd("Trouble lsp toggle win.position=right")
end, { desc = "LSP definitions / references /..." })
vim.keymap.set("n", "<leader>ql", function()
vim.cmd("Trouble qflist toggle")
end, { desc = "Quickfix list (trouble)" })
end,
},
{
"typst-preview",
after = function()
require("typst-preview").setup({
dependencies_bin = {
["typst-preview"] = nixCats("bin.tinymist"),
["websocat"] = nixCats("bin.websocat"),
},
})
end,
},
{
"toggleterm.nvim",
after = function()
require("toggleterm").setup({
shade_terminals = false,
})
vim.keymap.set({ "n", "t", "v" }, "<C-l>", function()
vim.cmd("ToggleTerm direction=float")
end)
vim.keymap.set("n", "<leader>tv", function()
vim.cmd("ToggleTerm direction=vertical")
end)
vim.keymap.set("n", "<leader>tt", function()
vim.cmd("ToggleTerm direction=horizontal")
end)
vim.keymap.set("n", "<leader>ts", function()
vim.cmd("TermSelect")
end)
end,
},
{
"mini.ai",
event = "BufEnter",
after = function()
require("mini.ai").setup()
end
},
{
"mini.surround",
event = "BufEnter",
after = function()
require("mini.surround").setup()
end
},
{
"mini.starter",
after = function ()
require("mini.starter").setup()
end
},
{
"mini.notify",
event = "BufEnter",
after = function ()
require("mini.notify").setup({
lsp_progress = { enable = false }
})
end
},
{
"mini.trailspace",
event = "BufEnter",
after = function ()
require("mini.trailspace").setup()
end
},
{
"cellular-automaton.nvim",
cmd = "CellularAutomaton",
},
{
"indent-blankline.nvim",
after = function ()
require("ibl").setup({
indent = {
char = "",
tab_char = "",
},
scope = { show_start = false, show_end = false },
exclude = {
filetypes = {
"help",
"ministarter",
"Trouble",
"trouble",
"toggleterm",
},
},
}
)
end
},
{
"mini.bufremove",
event = "BufEnter",
after = function ()
require("mini.bufremove").setup()
vim.keymap.set({"n", "v"}, "<leader>bd", function ()
MiniBufremove.delete()
end)
end
},
{
"mini.hipatterns",
event = "BufEnter",
after = function ()
require("mini.hipatterns").setup()
end
},
{
"gitsigns.nvim",
event = "BufEnter",
after = function ()
require('gitsigns').setup{
on_attach = function(bufnr)
local gitsigns = require('gitsigns')
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map('n', ']c', function()
if vim.wo.diff then
vim.cmd.normal({']c', bang = true})
else
gitsigns.nav_hunk('next')
end
end)
map('n', '[c', function()
if vim.wo.diff then
vim.cmd.normal({'[c', bang = true})
else
gitsigns.nav_hunk('prev')
end
end)
-- Actions
map('n', '<leader>gs', gitsigns.stage_hunk)
map('n', '<leader>gr', gitsigns.reset_hunk)
map('v', '<leader>gs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
map('v', '<leader>gr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
map('n', '<leader>gS', gitsigns.stage_buffer)
map('n', '<leader>gu', gitsigns.undo_stage_hunk)
map('n', '<leader>gR', gitsigns.reset_buffer)
map('n', '<leader>gp', gitsigns.preview_hunk)
map('n', '<leader>gb', function() gitsigns.blame_line{full=true} end)
map('n', '<leader>gb', gitsigns.toggle_current_line_blame)
map('n', '<leader>gd', gitsigns.diffthis)
map('n', '<leader>gD', function() gitsigns.diffthis('~') end)
map('n', '<leader>gtd', gitsigns.toggle_deleted)
-- Text object
map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
end
} }
end
},
{
"neogit",
cmd = "Neogit",
after = function ()
require("neogit").setup({
graph_style = "unicode",
integrations = {
telescope = true,
diffview = true
}
})
end
},
{
"diffiew.nvim",
cmd = {"DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles", "DiffviewRefresh"},
},
{
"barbecue.nvim",
event = "BufEnter",
after = function()
require("barbecue").setup()
-- triggers CursorHold event faster
vim.opt.updatetime = 200
require("barbecue").setup({
create_autocmd = false, -- prevent barbecue from updating itself automatically
})
vim.api.nvim_create_autocmd({
"WinResized",
"BufWinEnter",
"CursorHold",
"InsertLeave",
-- include this if you have set `show_modified` to `true`
"BufModifiedSet",
}, {
group = vim.api.nvim_create_augroup("barbecue.updater", {}),
callback = function()
require("barbecue.ui").update()
end,
})
end
},
{
"undotree",
cmd = "UndotreeToggle"
}
}

39
lua/plugins/oil.lua Normal file
View file

@ -0,0 +1,39 @@
return {
"oil.nvim",
after = function()
require("oil").setup({
columns = {
"size",
"icon",
},
use_default_keymaps = false,
keymaps = {
["J"] = "actions.parent",
["Q"] = "actions.close",
["<C-h>"] = "actions.select_split",
["<C-l>"] = "actions.refresh",
["<C-p>"] = "actions.preview",
["<C-s>"] = "actions.select_vsplit",
["<C-t>"] = "actions.select_tab",
["<CR>"] = "actions.select",
["K"] = "actions.select",
["_"] = "actions.open_cwd",
["`"] = "actions.cd",
["g."] = "actions.toggle_hidden",
["g?"] = "actions.show_help",
["g\\"] = "actions.toggle_trash",
["gs"] = "actions.change_sort",
["gx"] = "actions.open_external",
["~"] = "actions.tcd",
},
})
vim.keymap.set("n", "<leader>e", function()
vim.cmd("Oil")
end, { desc = "Open file explorer in current file directory" })
vim.keymap.set("n", "<leader>fe", function()
vim.cmd("Oil " .. vim.fn.getcwd())
end, { desc = "Open file explorer in current working directory" })
end,
}

36
lua/plugins/telescope.lua Normal file
View file

@ -0,0 +1,36 @@
return {
"telescope.nvim",
after = function()
require("telescope").setup({
extensions = {
["ui-select"] = {
require("telescope.themes").get_dropdown({}),
},
},
})
require("telescope").load_extension("ui-select")
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader> ", function()
local is_git = vim.fn.finddir(".git", vim.fn.getcwd() .. ";")
if is_git then
builtin.git_files()
else
builtin.find_files()
end
end, { desc = "Grep through all files tracked by git, or fall back to just cwd" })
vim.keymap.set("n", "<leader>ff", builtin.find_files, { desc = "Grep through all files in cwd" })
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action)
vim.keymap.set("n", "<leader>/", builtin.live_grep)
vim.keymap.set("n", "<leader>k", builtin.buffers)
vim.keymap.set("n", "<leader>gd", builtin.lsp_definitions, { desc = "Go to LSP definition" })
vim.keymap.set("n", "<leader>gi", builtin.lsp_implementations, { desc = "Go to implementations" })
vim.keymap.set("n", "<leader>j", builtin.lsp_document_symbols, { desc = "Search through document symbols" })
vim.keymap.set("n", "<leader>fs", builtin.lsp_workspace_symbols, { desc = "Search through entire workspace symbols" })
vim.keymap.set("n", "<leader>fd", builtin.diagnostics, { desc = "Search through LSP diagnostics" })
end,
priority = 60
}

27
lua/scripts/autoroot.lua Normal file
View file

@ -0,0 +1,27 @@
-- Array of file names indicating root directory. Modify to your liking.
local root_names = { '.git', 'Makefile', '.svn', '.hg' }
-- Cache to use for speed up (at cost of possibly outdated results)
local root_cache = {}
local set_root = function()
-- Get directory path to start search from
local path = vim.api.nvim_buf_get_name(0)
if path == "" then return end
path = vim.fs.dirname(path)
-- Try cache and resort to searching upward for root directory
local root = root_cache[path]
if root == nil then
local root_file = vim.fs.find(root_names, { path = path, upward = true })[1]
if root_file == nil then return end
root = vim.fs.dirname(root_file)
root_cache[path] = root
end
-- Set current directory
vim.fn.chdir(root)
end
local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {})
vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root })