1
0
Fork 0

Live grep enhancements

This commit is contained in:
Gürkan 2023-04-27 17:39:09 +02:00
parent 36cb3c2f3b
commit 4f15ba03c8
2 changed files with 69 additions and 19 deletions

3
README Normal file
View File

@ -0,0 +1,3 @@
This is my neovim config, nothing much to explain.
It's pretty much documented, so you can check it out.

85
nix.vim
View File

@ -126,27 +126,57 @@ vim.keymap.set('i', '<C-Up>', "<Plug>(copilot-previous)", {})
-- Telescope
local actions = require("telescope.actions")
local fb_actions = require "telescope._extensions.file_browser.actions"
-- A helper tool from https://github.com/nvim-telescope/telescope.nvim/issues/2201
-- We can select a directory and then grep in it
local ts_select_dir_for_grep = function(prompt_bufnr)
local action_state = require("telescope.actions.state")
local fb = require("telescope").extensions.file_browser
local live_grep = require("telescope.builtin").live_grep
local current_line = action_state.get_current_line()
fb.file_browser({
files = false,
depth = false,
attach_mappings = function(prompt_bufnr)
require("telescope.actions").select_default:replace(function()
local entry_path = action_state.get_selected_entry().Path
local dir = entry_path:is_dir() and entry_path or entry_path:parent()
local relative = dir:make_relative(vim.fn.getcwd())
local absolute = dir:absolute()
live_grep({
results_title = relative .. "/",
cwd = absolute,
default_text = current_line,
})
end)
return true
end,
})
end
require('telescope').setup{
extensions = {
file_browser = {
theme = "ivy",
-- disables netrw and use telescope-file-browser in its place
hijack_netrw = true,
cwd_to_path = true,
grouped = true,
hidden = true,
files = true,
auto_depth = 4,
git_status = true,
mappings = {
["i"] = {
["<C-Up>"] = fb_actions.goto_parent_dir
extensions = {
file_browser = {
theme = "ivy",
-- disables netrw and use telescope-file-browser in its place
hijack_netrw = true,
cwd_to_path = true,
grouped = true,
hidden = true,
files = true,
auto_depth = 4,
git_status = true,
mappings = {
["i"] = {
["<C-Up>"] = fb_actions.goto_parent_dir
},
},
},
},
},
defaults = {
dynamic_preview_title = true,
defaults = {
dynamic_preview_title = true,
mappings = {
i = {
-- Quit via Esc in insert mode
@ -154,6 +184,18 @@ defaults = {
},
},
},
pickers = {
live_grep = {
mappings = {
i = {
["<C-f>"] = ts_select_dir_for_grep,
},
n = {
["<C-f>"] = ts_select_dir_for_grep,
},
},
},
},
}
require("telescope").load_extension "file_browser"
@ -247,12 +289,17 @@ require('lualine').setup(
tabline = {
lualine_a = {
{ 'buffers',
show_filename_only = false,
symbols = {
modified = ' +'
}
},
},
},
-- Couldn't find a sane bufferline formatter
lualine_z = {
{ 'filename',
path = 1
}
},
},
sections = {
lualine_a = {'mode'},