Feat: add telescope file_browser and rewrite keymap

This commit is contained in:
Bertrand Benjamin 2022-08-20 06:16:14 +02:00
parent 4324070cac
commit 01d09bc9c0
2 changed files with 80 additions and 34 deletions

View File

@ -1,3 +1,7 @@
local status, telescope = pcall(require, "telescope")
if (not status) then return end
local builtin = require("telescope.builtin")
local previewers = require('telescope.previewers') local previewers = require('telescope.previewers')
local Job = require('plenary.job') local Job = require('plenary.job')
local new_maker = function(filepath, bufnr, opts) local new_maker = function(filepath, bufnr, opts)
@ -19,10 +23,15 @@ local new_maker = function(filepath, bufnr, opts)
}):sync() }):sync()
end end
require('telescope').setup { local fb_actions = require "telescope".extensions.file_browser.actions
local function telescope_buffer_dir()
return vim.fn.expand('%:p:h')
end
telescope.setup {
defaults = { defaults = {
buffer_previewer_maker = new_maker, buffer_previewer_maker = new_maker,
file_ignore_patterns = {"**/*.pdf"}, file_ignore_patterns = { "**/*.pdf" },
}, },
extensions = { extensions = {
fzf = { fzf = {
@ -31,16 +40,52 @@ require('telescope').setup {
override_file_sorter = true, -- override the file sorter override_file_sorter = true, -- override the file sorter
case_mode = "smart_case", -- or "ignore_case" or "respect_case" case_mode = "smart_case", -- or "ignore_case" or "respect_case"
-- the default case_mode is "smart_case" -- the default case_mode is "smart_case"
} },
file_browser = {
theme = "dropdown",
-- disables netrw and use telescope-file-browser in its place
hijack_netrw = true,
mappings = {
["n"] = {
-- your custom normal mode mappings
["h"] = fb_actions.goto_parent_dir,
},
},
},
} }
} }
require('telescope').load_extension('fzf') telescope.load_extension('fzf')
telescope.load_extension('file_browser')
local map = vim.api.nvim_set_keymap
-- Find files using Telescope command-line sugar.
map('n', '<leader>e', '<cmd>Telescope find_files<cr>', {})
map('n', '<leader>g', '<cmd>Telescope live_grep<cr>', {})
map('n', '<leader>b', '<cmd>Telescope buffers<cr>', {})
map('n', '<leader>h', '<cmd>Telescope help_tags<cr>', {})
-- keymaps
vim.keymap.set('n', '<leader>e',
function()
builtin.find_files({
})
end)
vim.keymap.set('n', '<leader>g', function()
builtin.live_grep()
end)
vim.keymap.set('n', '<leader>b', function()
builtin.buffers()
end)
vim.keymap.set('n', '<leader>h', function()
builtin.resume()
end)
-- vim.keymap.set('n', '<leader>d', function()
-- builtin.diagnostics()
-- end)
vim.keymap.set("n", "<leader>fb", function()
telescope.extensions.file_browser.file_browser({
path = "%:p:h",
cwd = telescope_buffer_dir(),
respect_gitignore = false,
hidden = true,
grouped = true,
previewer = false,
initial_mode = "normal",
layout_config = { height = 40 }
})
end)

View File

@ -93,6 +93,7 @@ return packer.startup(function(use)
} }
use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }
use { "nvim-telescope/telescope-file-browser.nvim" }
use { use {
'lervag/vimtex', 'lervag/vimtex',