fuzzy find files no plugins
This commit is contained in:
parent
c144250c75
commit
4b96003de4
1 changed files with 38 additions and 0 deletions
38
lua/set.lua
38
lua/set.lua
|
|
@ -45,3 +45,41 @@ vim.g.clipboard = {
|
||||||
},
|
},
|
||||||
cache_enable = 0,
|
cache_enable = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function fzf_open_terminal()
|
||||||
|
local tmp = vim.fn.tempname()
|
||||||
|
local cwd = vim.fn.getcwd()
|
||||||
|
|
||||||
|
local rg = [[rg --files --hidden --glob "!.git/**" --glob "!node_modules/**" --glob "!.angular/**"]]
|
||||||
|
local awk = [[awk -F'/' '{dir = (NF>1 ? substr($0, 1, length($0)-length($NF)-1) : "."); printf("%s [%s]\t%s\n", $NF, dir, $0)}']]
|
||||||
|
local inner = string.format("cd %s && %s | %s | fzf --height 40%% > %s",
|
||||||
|
vim.fn.shellescape(cwd), rg, awk, vim.fn.shellescape(tmp))
|
||||||
|
|
||||||
|
vim.cmd('belowright split')
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_win_set_buf(0, bufnr)
|
||||||
|
|
||||||
|
-- pass argv form to avoid fish parsing issues
|
||||||
|
vim.fn.termopen({'bash', '-ic', inner}, {
|
||||||
|
on_exit = function()
|
||||||
|
local lines = vim.fn.readfile(tmp)
|
||||||
|
os.remove(tmp)
|
||||||
|
if #lines == 0 then
|
||||||
|
vim.schedule(function()
|
||||||
|
if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, {force=true}) end
|
||||||
|
end)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local sel = lines[1]:match("\t(.*)$") or lines[1]
|
||||||
|
vim.schedule(function()
|
||||||
|
|
||||||
|
if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, {force=true}) end
|
||||||
|
vim.cmd('edit ' .. vim.fn.fnameescape(sel))
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.cmd('startinsert')
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set('n', '<leader>o', fzf_open_terminal, {noremap=true, silent=true})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue