require("telescope").setup { defaults = { vimgrep_arguments = { "rg", "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", "--smart-case", }, path_display = { shorten = 4 }, }, } -- Load fzf extension to imporve performance pcall(require("telescope").load_extension, "fzf") -- Glob pattern searcher local function live_grep_with_glob() vim.ui.input({ prompt = "Glob pattern: ", default = "/home/user/Work/root/ivideon/audio_storage/", -- Optional default value }, function(input) if input then require('telescope.builtin').live_grep({ -- glob_pattern = input, search_dirs = { input } }) end end) end local function live_grep_in_current_dir() -- Get currentp path local search_dirs = { vim.fn.expand('%:p') } -- Extract path from table local current_dir = search_dirs[1] -- Get path, cutting last entry (current file) local result = current_dir:match(".*/") vim.ui.input({ prompt = "Glob pattern: ", default = result, -- Optional default value }, function(input) if input then require('telescope.builtin').live_grep({ search_dirs = { input } }) end end) end -- Function for copying current file path local function copy_current_file_path() local filepath = vim.fn.expand('%:p') vim.fn.setreg("+", filepath) print("Copied: " .. filepath) end -- Function for gettings snapshot of current cursor position 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] local output = string.format("%s:%d:%d", filepath, line, col) vim.fn.setreg("+", output) print("Copied: " .. output) end local builtin = require("telescope.builtin") local keymap = vim.keymap -- Create a Neovim command vim.api.nvim_create_user_command('TelescopeGrepGlob', live_grep_with_glob, {}) keymap.set("n", "ff", builtin.find_files, { desc = "FZF: find files in cwd" }) keymap.set("n", "fml", builtin.marks, { desc = "FZF: find marks list" }) keymap.set("n", "fmp", builtin.man_pages, { desc = "FZF: find available man pages" }) keymap.set("n", "fg", builtin.live_grep, { desc = "FZF: find string in cwd" }) keymap.set("n", "fs", builtin.grep_string, { desc = "FZF: find string under cursor" }) keymap.set("n", "fb", builtin.buffers, { desc = "FZF: display opened buffers" }) keymap.set("n", "fh", builtin.help_tags, { desc = "FZF: display help tags" }) keymap.set("n", "ft", "TodoTelescope", { desc = "FZF: display TODO comments" }) keymap.set("n", "fds", builtin.lsp_document_symbols, { desc = "Grep: Document symbols" }) keymap.set('n', 'fp', live_grep_with_glob, { desc = 'Live grep with glob pattern' }) keymap.set('n', 'fcp', live_grep_in_current_dir, { desc = 'Live grep in current directory' }) keymap.set('n', 'ccp', copy_file_path_and_position, {desc = "Copy cursor position"}) keymap.set('n', 'ccd', copy_current_file_path, { desc = 'Live grep in current directory' }) -- Live grep in current file vim.keymap.set('n', 'fcf', function() require('telescope.builtin').live_grep({ search_dirs = { vim.fn.expand('%:p') }, -- Current file's full path -- disable_coordinates = true, -- Hide line/column numbers -- fname_width = 0, -- Hide filename column path_display = { 'hidden' }, }) end, { desc = 'Live grep in current file' })