[Telescope] Add tons more functionality. <leader>f to check it out
This commit is contained in:
parent
78e2309f2f
commit
541fe69d57
@ -1,50 +1,3 @@
|
||||
local actions = require('telescope.actions')
|
||||
local action_state = require('telescope.actions.state')
|
||||
|
||||
-- Custom function for search and replace using Telescope
|
||||
-- test
|
||||
function _G.search_and_replace()
|
||||
local current_file = vim.fn.expand('%:p')
|
||||
local query = vim.fn.input('Enter search pattern: ')
|
||||
|
||||
-- Create the Telescope prompt with custom mappings
|
||||
require('telescope.builtin').find_files({
|
||||
prompt_title = 'Search and Replace',
|
||||
cwd = vim.loop.cwd(),
|
||||
hidden = true,
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
local selection = action_state.get_selected_entry()
|
||||
|
||||
-- Get the replace pattern from user
|
||||
local replace_query = vim.fn.input('Replace with: ', '')
|
||||
|
||||
if not replace_query == '' then
|
||||
local args = { query, replace_query }
|
||||
|
||||
-- Open a terminal buffer to run the search and replace command
|
||||
require('telescope.builtin').terminal_job({
|
||||
cmd = {
|
||||
'sh', '-c',
|
||||
string.format(
|
||||
"grep -rl '%s' . | xargs sed -i 's/%s/%s/g'",
|
||||
table.concat(args, "'"),
|
||||
query,
|
||||
replace_query
|
||||
)
|
||||
},
|
||||
cwd = vim.fn.expand('%:p:h'),
|
||||
})
|
||||
end
|
||||
|
||||
return true
|
||||
end)
|
||||
|
||||
return true
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
return {
|
||||
-- fuzzy finder
|
||||
"nvim-telescope/telescope.nvim",
|
||||
@ -77,11 +30,35 @@ return {
|
||||
opts.desc = "telescope buffers"
|
||||
vim.keymap.set("n", "<leader>fb", builtin.buffers, opts)
|
||||
|
||||
opts.desc = "telescope nvim functions"
|
||||
opts.desc = "Show nvim functions"
|
||||
vim.keymap.set("n", "<leader>fh", builtin.help_tags, opts)
|
||||
|
||||
-- Recent Commands
|
||||
opts.desc = "Show recent commands"
|
||||
vim.keymap.set('n', '<leader>frc', ':Telescope command_history<CR>', opts)
|
||||
|
||||
-- Search and replace
|
||||
|
||||
-- Recent Searches
|
||||
opts.desc = "Show recent searches"
|
||||
vim.keymap.set('n', '<leader>frs', ':Telescope search_history<CR>', opts)
|
||||
|
||||
-- Old Files
|
||||
opts.desc = "Show recent files"
|
||||
vim.keymap.set('n', '<leader>frf', ':Telescope oldfiles<CR>', opts)
|
||||
|
||||
-- Quickfix Items
|
||||
opts.desc = "Show quickfix items"
|
||||
vim.keymap.set('n', '<leader>fq', ':Telescope quickfix<CR>', opts)
|
||||
|
||||
-- Spell Suggestions
|
||||
opts.desc = "Show spell suggestions"
|
||||
vim.keymap.set('n', '<leader>fs', ':Telescope spell_suggest<CR>', opts)
|
||||
|
||||
-- Diagnostics
|
||||
opts.desc = "Show diagnostics"
|
||||
vim.keymap.set('n', '<leader>fd', ':Telescope diagnostics<CR>', opts)
|
||||
|
||||
-- Implementations
|
||||
opts.desc = "Show implementations"
|
||||
vim.keymap.set('n', '<leader>fi', ':Telescope lsp_implementations<CR>', opts)
|
||||
end,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user