Telescope: Add bindings for postitions in file
This commit is contained in:
parent
465aeabd4f
commit
22def9e8ad
1 changed files with 54 additions and 2 deletions
|
|
@ -1,5 +1,14 @@
|
||||||
require("telescope").setup {
|
require("telescope").setup {
|
||||||
defaults = {
|
defaults = {
|
||||||
|
vimgrep_arguments = {
|
||||||
|
"rg",
|
||||||
|
"--color=never",
|
||||||
|
"--no-heading",
|
||||||
|
"--with-filename",
|
||||||
|
"--line-number",
|
||||||
|
"--column",
|
||||||
|
"--smart-case",
|
||||||
|
},
|
||||||
path_display = { shorten = 4 },
|
path_display = { shorten = 4 },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -11,7 +20,7 @@ pcall(require("telescope").load_extension, "fzf")
|
||||||
local function live_grep_with_glob()
|
local function live_grep_with_glob()
|
||||||
vim.ui.input({
|
vim.ui.input({
|
||||||
prompt = "Glob pattern: ",
|
prompt = "Glob pattern: ",
|
||||||
default = "/home/user/Work/root/ivideon/audio_saver", -- Optional default value
|
default = "/home/user/Work/root/ivideon/audio_storage/", -- Optional default value
|
||||||
}, function(input)
|
}, function(input)
|
||||||
if input then
|
if input then
|
||||||
require('telescope.builtin').live_grep({
|
require('telescope.builtin').live_grep({
|
||||||
|
|
@ -22,6 +31,46 @@ local function live_grep_with_glob()
|
||||||
end)
|
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 builtin = require("telescope.builtin")
|
||||||
local keymap = vim.keymap
|
local keymap = vim.keymap
|
||||||
|
|
@ -39,9 +88,12 @@ keymap.set("n", "<leader>fh", builtin.help_tags, { desc = "FZF: display help tag
|
||||||
keymap.set("n", "<leader>ft", "<cmd>TodoTelescope<cr>", { desc = "FZF: display TODO comments" })
|
keymap.set("n", "<leader>ft", "<cmd>TodoTelescope<cr>", { desc = "FZF: display TODO comments" })
|
||||||
keymap.set("n", "<leader>fds", builtin.lsp_document_symbols, { desc = "Grep: Document symbols" })
|
keymap.set("n", "<leader>fds", builtin.lsp_document_symbols, { desc = "Grep: Document symbols" })
|
||||||
keymap.set('n', '<leader>fp', live_grep_with_glob, { desc = 'Live grep with glob pattern' })
|
keymap.set('n', '<leader>fp', live_grep_with_glob, { desc = 'Live grep with glob pattern' })
|
||||||
|
keymap.set('n', '<leader>fcp', live_grep_in_current_dir, { desc = 'Live grep in current directory' })
|
||||||
|
keymap.set('n', '<leader>ccp', copy_file_path_and_position, {desc = "Copy cursor position"})
|
||||||
|
keymap.set('n', '<leader>ccd', copy_current_file_path, { desc = 'Live grep in current directory' })
|
||||||
|
|
||||||
-- Live grep in current file
|
-- Live grep in current file
|
||||||
vim.keymap.set('n', '<leader>fc', function()
|
vim.keymap.set('n', '<leader>fcf', function()
|
||||||
require('telescope.builtin').live_grep({
|
require('telescope.builtin').live_grep({
|
||||||
search_dirs = { vim.fn.expand('%:p') }, -- Current file's full path
|
search_dirs = { vim.fn.expand('%:p') }, -- Current file's full path
|
||||||
-- disable_coordinates = true, -- Hide line/column numbers
|
-- disable_coordinates = true, -- Hide line/column numbers
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue