Configure preview window with:
autocmd User TelescopePreviewerLoaded setlocal wrap
autocmd User TelescopePreviewerLoaded setlocal number
file_maker example: Use regex highlighting for certain filetype like `*min.js` because they slow
down things with treesitter highlighter. Just a snippet for tests. We will do an extension :)
local previewers = require('telescope.previewers')
local putils = require('telescope.previewers.utils')
local pfiletype = require('plenary.filetype')
local _bad = { '.*%.min%.js' }
local bad_files = function(filepath)
for _, v in ipairs(_bad) do
if filepath:match(v) then
return true
end
end
return false
end
local new_maker = function(filepath, bufnr, bufname, use_ft_detect, callback)
if use_ft_detect == nil then use_ft_detect = true end
if bad_files(filepath) then
previewers.buffer_previewer_maker(filepath, bufnr, bufname, false, callback)
local ft = pfiletype.detect(filepath)
putils.regex_highlighter(bufnr, ft)
else
previewers.buffer_previewer_maker(filepath, bufnr, bufname, use_ft_detect, callback)
end
end
require('telescope').setup {
defaults = {
buffer_previewer_maker = new_maker,
}
}
78 lines
3.0 KiB
VimL
78 lines
3.0 KiB
VimL
" Sets the highlight for selected items within the picker.
|
|
highlight default link TelescopeSelection Visual
|
|
highlight default link TelescopeSelectionCaret TelescopeSelection
|
|
highlight default link TelescopeMultiSelection Type
|
|
|
|
" "Normal" in the floating windows created by telescope.
|
|
highlight default link TelescopeNormal Normal
|
|
|
|
" Border highlight groups.
|
|
" Use TelescopeBorder to override the default.
|
|
" Otherwise set them specifically
|
|
highlight default link TelescopeBorder TelescopeNormal
|
|
highlight default link TelescopePromptBorder TelescopeBorder
|
|
highlight default link TelescopeResultsBorder TelescopeBorder
|
|
highlight default link TelescopePreviewBorder TelescopeBorder
|
|
|
|
" Used for highlighting characters that you match.
|
|
highlight default link TelescopeMatching Special
|
|
|
|
" Used for the prompt prefix
|
|
highlight default link TelescopePromptPrefix Identifier
|
|
|
|
" Used for highlighting the matched line inside Previewer. Works only for (vim_buffer_ previewer)
|
|
highlight default link TelescopePreviewLine Visual
|
|
highlight default link TelescopePreviewMatch Search
|
|
|
|
" Used for Picker specific Results highlighting
|
|
highlight default link TelescopeResultsClass Function
|
|
highlight default link TelescopeResultsConstant Constant
|
|
highlight default link TelescopeResultsField Function
|
|
highlight default link TelescopeResultsFunction Function
|
|
highlight default link TelescopeResultsMethod Method
|
|
highlight default link TelescopeResultsOperator Operator
|
|
highlight default link TelescopeResultsStruct Struct
|
|
highlight default link TelescopeResultsVariable SpecialChar
|
|
|
|
highlight default link TelescopeResultsLineNr LineNr
|
|
highlight default link TelescopeResultsIdentifier Identifier
|
|
highlight default link TelescopeResultsNumber Number
|
|
highlight default link TelescopeResultsComment Comment
|
|
highlight default link TelescopeResultsSpecialComment SpecialComment
|
|
|
|
" This is like "<C-R>" in your terminal.
|
|
" To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch)
|
|
cnoremap <silent> <Plug>(TelescopeFuzzyCommandSearch) <C-\>e
|
|
\ "lua require('telescope.builtin').command_history {
|
|
\ default_text = [=[" . escape(getcmdline(), '"') . "]=]
|
|
\ }"<CR><CR>
|
|
|
|
" Telescope builtin lists
|
|
function! s:telescope_complete(...)
|
|
return join(luaeval('vim.tbl_keys(require("telescope.builtin"))'), "\n")
|
|
endfunction
|
|
|
|
" TODO: If the lua datatype contains complex type,It will cause convert to
|
|
" viml datatype failed. So current doesn't support config telescope.themes
|
|
function! s:load_command(builtin,...) abort
|
|
let opts = {}
|
|
|
|
" range command args
|
|
" if arg in lua code is table type,we split command string by `,` to vimscript
|
|
" list type.
|
|
for arg in a:000
|
|
let opt = split(arg,'=')
|
|
if opt[0] == 'find_command' || opt[0] == 'vimgrep_arguments'
|
|
let opts[opt[0]] = split(opt[1],',')
|
|
else
|
|
let opts[opt[0]] = opt[1]
|
|
endif
|
|
endfor
|
|
|
|
let telescope = v:lua.require('telescope.builtin')
|
|
call telescope[a:builtin](opts)
|
|
endfunction
|
|
|
|
" Telescope Commands with complete
|
|
command! -nargs=+ -complete=custom,s:telescope_complete Telescope call s:load_command(<f-args>)
|