fzf-lua: Trying to add fzf-lua and replace telescope
This commit is contained in:
parent
a4ea5c0f48
commit
d82f0dd634
2 changed files with 138 additions and 0 deletions
129
lua/custom/fzf_lua.lua
Normal file
129
lua/custom/fzf_lua.lua
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
local fzf_lua = require("fzf-lua")
|
||||
|
||||
fzf_lua.setup({
|
||||
winopts = {
|
||||
height = 0.85,
|
||||
width = 0.80,
|
||||
},
|
||||
fzf_opts = {
|
||||
['--layout'] = 'reverse-list',
|
||||
},
|
||||
files = {
|
||||
fd_opts = "--color=never --type f",
|
||||
rg_opts = "--color=never --files",
|
||||
},
|
||||
keymap = {
|
||||
builtin = {
|
||||
["<C-j>"] = "down",
|
||||
["<C-k>"] = "up",
|
||||
["<S-tab>"] = "toggle+up",
|
||||
["<tab>"] = "toggle+down",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- Glob pattern searcher
|
||||
local function live_grep_with_glob()
|
||||
vim.ui.input({
|
||||
prompt = "Glob pattern: ",
|
||||
default = "/home/user/Work/root/ivideon/audio_storage/",
|
||||
}, function(input)
|
||||
if input then
|
||||
fzf_lua.live_grep({
|
||||
cwd = input,
|
||||
})
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function live_grep_in_current_dir()
|
||||
local current_file = vim.fn.expand('%:p')
|
||||
local current_dir = current_file:match("(.*/)")
|
||||
|
||||
vim.ui.input({
|
||||
prompt = "Glob pattern: ",
|
||||
default = current_dir or vim.fn.getcwd(),
|
||||
}, function(input)
|
||||
if input then
|
||||
fzf_lua.live_grep({
|
||||
cwd = input,
|
||||
})
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function copy_current_file_path()
|
||||
local filepath = vim.fn.expand('%:p')
|
||||
vim.fn.setreg("+", filepath)
|
||||
print("Copied: " .. filepath)
|
||||
end
|
||||
|
||||
local function copy_file_path_and_position()
|
||||
local filepath = vim.fn.expand('%:p')
|
||||
local cursor_pos = vim.api.nvim_win_get_cursor(0)
|
||||
local line = cursor_pos[1]
|
||||
local col = cursor_pos[2] + 1 -- fzf-lua uses 1-indexed columns
|
||||
|
||||
local output = string.format("%s:%d:%d", filepath, line, col)
|
||||
vim.fn.setreg("+", output)
|
||||
print("Copied: " .. output)
|
||||
end
|
||||
|
||||
local function live_grep_in_quick_fix_list_files()
|
||||
local qf_items = vim.fn.getqflist()
|
||||
local files = {}
|
||||
|
||||
for _, item in ipairs(qf_items) do
|
||||
if item.bufnr > 0 then
|
||||
local filename = vim.api.nvim_buf_get_name(item.bufnr)
|
||||
if filename ~= "" then
|
||||
table.insert(files, filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #files > 0 then
|
||||
fzf_lua.live_grep({
|
||||
search_dirs = files,
|
||||
})
|
||||
else
|
||||
print("No files in quickfix list")
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command('FzfLuaGrepGlob', live_grep_with_glob, {})
|
||||
|
||||
local keymap = vim.keymap.set
|
||||
|
||||
keymap("n", "<leader>lf", function() fzf_lua.files() end, { desc = "FZF: find files in cwd" })
|
||||
keymap("n", "<leader>lg", function() fzf_lua.live_grep() end, { desc = "FZF: find string in cwd" })
|
||||
keymap("n", "<leader>ls", function() fzf_lua.grep_cword() end, { desc = "FZF: find string under cursor" })
|
||||
keymap("n", "<leader>lb", function() fzf_lua.buffers() end, { desc = "FZF: display opened buffers" })
|
||||
keymap("n", "<leader>lh", function() fzf_lua.help_tags() end, { desc = "FZF: display help tags" })
|
||||
|
||||
-- Your custom commands
|
||||
keymap('n', '<leader>lp', live_grep_with_glob, { desc = 'Live grep with glob pattern' })
|
||||
keymap('n', '<leader>lcp', live_grep_in_current_dir, { desc = 'Live grep in current directory' })
|
||||
-- keymap('n', '<leader>ccp', copy_file_path_and_position, { desc = "Copy cursor position" })
|
||||
-- keymap('n', '<leader>ccd', copy_current_file_path, { desc = 'Copy current file path' })
|
||||
keymap('n', '<leader>lq', live_grep_in_quick_fix_list_files, { desc = "Live grep in quickfix files" })
|
||||
|
||||
keymap('n', '<leader>lcf', function()
|
||||
fzf_lua.live_grep({
|
||||
cwd = vim.fn.expand('%:p:h'),
|
||||
search = '',
|
||||
fzf_cli_args = '--no-sort',
|
||||
})
|
||||
end, { desc = "Live grep in current file" })
|
||||
|
||||
keymap("n", "<leader>lml", function() fzf_lua.marks() end, { desc = "FZF: find marks list" })
|
||||
keymap("n", "<leader>lmp", function() fzf_lua.man_pages() end, { desc = "FZF: find available man pages" })
|
||||
keymap("n", "<leader>lds", function() fzf_lua.lsp_document_symbols() end, { desc = "Grep: Document symbols" })
|
||||
|
||||
keymap("n", "<leader>lt", function()
|
||||
fzf_lua.grep({
|
||||
prompt = 'Todo❯ ',
|
||||
search = 'TODO|FIXME|XXX|HACK|BUG|NOTE|PERF|OPTIMIZE',
|
||||
no_esc = true,
|
||||
})
|
||||
end, { desc = "FZF: display TODO comments" })
|
||||
9
lua/custom/plugins/fzf_lua.lua
Normal file
9
lua/custom/plugins/fzf_lua.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
return {
|
||||
"ibhagwan/fzf-lua",
|
||||
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||
opts = {},
|
||||
config = function()
|
||||
require "custom.fzf_lua"
|
||||
end
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue