local previewers = require('telescope.previewers') local Job = require('plenary.job') local new_maker = function(filepath, bufnr, opts) filepath = vim.fn.expand(filepath) Job:new({ command = 'file', args = { '--mime-type', '-b', filepath }, on_exit = function(j) local mime_type = vim.split(j:result()[1], '/')[1] if mime_type == "text" then previewers.buffer_previewer_maker(filepath, bufnr, opts) else -- maybe we want to write something to the buffer here vim.schedule(function() vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { 'BINARY' }) end) end end }):sync() end require('telescope').setup { defaults = { buffer_previewer_maker = new_maker, file_ignore_patterns = {"**/*.pdf"}, } } local map = vim.api.nvim_set_keymap -- Find files using Telescope command-line sugar. map('n', 'e', 'Telescope find_files', {}) map('n', 'g', 'Telescope live_grep', {}) map('n', 'b', 'Telescope buffers', {}) map('n', 'h', 'Telescope help_tags', {})