robin/ivy

my custom neovim config

git clone https://git.robinwobin.dev/robin/ivy

robinkeymaps: sort into files in `config/plugin/keymaps/`4fb7125

main
879 B37 linesraw
1local function findfile(fname)
2  local ftype = string.sub(fname, -1) == "/" and "directory" or "file"
3
4  if fname:sub(0, 1) == "/" then
5    return fname
6  end
7
8  if ftype == "directory" then
9    fname = fname:sub(0, -2)
10  end
11
12  local currentfile = vim.api.nvim_buf_get_name(0)
13  local root = vim.fn.isdirectory(currentfile) == 1 and currentfile
14    or vim.fs.dirname(currentfile)
15  local stop = vim.fs.dirname(vim.fn.getcwd(0))
16
17  local matches = vim.fs.find(fname, {
18    type = ftype,
19    upward = true,
20    path = root,
21    stop = stop,
22  })
23  if #matches > 0 then
24    return matches[1]
25  end
26
27  return vim.fs.joinpath(root, fname)
28end
29vim.keymap.set("n", "gf", function()
30  local fname = vim.fn.expand("<cfile>")
31  ---@cast fname string?
32  if not fname then
33    return
34  end
35  local path = findfile(fname)
36  vim.cmd.edit({ path, magic = { file = false, bar = false } })
37end)