Skip to content

Commit

Permalink
[neovim] Show paths in Telescope filename-first
Browse files Browse the repository at this point in the history
  • Loading branch information
denisw committed Apr 12, 2024
1 parent 6d3a12c commit 97b1a3e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion neovim/.config/nvim/lua/plugins/navigation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,33 @@ return {
},
lazy = false,
config = function()
-- Display entry text after two tabs as comment.
-- Used to display file paths as filename followed by greyed-out path.
-- https://github.com/nvim-telescope/telescope.nvim/issues/2014#issuecomment-1873229658
vim.api.nvim_create_autocmd("FileType", {
pattern = "TelescopeResults",
callback = function(ctx)
vim.api.nvim_buf_call(ctx.buf, function()
vim.fn.matchadd("TelescopeParent", "\t\t.*$")
vim.api.nvim_set_hl(0, "TelescopeParent", { link = "Comment" })
end)
end,
})

local function filename_first_path_display(_, path)
local tail = vim.fs.basename(path)
local parent = vim.fs.dirname(path)
if parent == "." then
return tail
else
return string.format("%s\t\t%s", tail, parent)
end
end

require("telescope").setup {
defaults = {
path_display = filename_first_path_display,
file_ignore_patterns = { "^.git/" },
mappings = {
i = {
["<esc>"] = "close",
Expand All @@ -94,7 +119,6 @@ return {
["<c-t>"] = require("trouble.providers.telescope").open_with_trouble,
},
},
file_ignore_patterns = { "^.git/" },
},
pickers = {
buffers = {
Expand Down Expand Up @@ -125,6 +149,7 @@ return {
},
}
}

local builtin = require("telescope.builtin")
vim.keymap.set("n", "<C-p>", builtin.find_files, {})
vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
Expand Down

0 comments on commit 97b1a3e

Please sign in to comment.