nvim: Remove telescope, use fzf directly

This commit is contained in:
doyle 2023-01-05 12:05:48 +11:00
parent e0a3120a03
commit afd77e38e9

View File

@ -12,25 +12,9 @@ call plug#begin(stdpath('config') . '/plugged')
" Plug 'https://github.com/nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " Plug 'https://github.com/nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'https://github.com/bfrg/vim-cpp-modern' Plug 'https://github.com/bfrg/vim-cpp-modern'
" Telescope file picker, sorter and previewer " FZF
Plug 'https://github.com/nvim-lua/plenary.nvim' Plug 'junegunn/fzf'
Plug 'https://github.com/nvim-telescope/telescope.nvim' Plug 'junegunn/fzf.vim'
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }
" nvim-lspconfig sets up sane defaults for LSP servers (i.e. clangd)
" nvim-cmp is a more powerful autocomplete engine
" LuaSnip allow writing snippets into the buffer, we can power the snippets from LSP
" cmp-nvim-lsp preset capability flags to request more powerful autocomplete from LSP server
" cmp_luasnip a LuaSnip addon that provides a completion source to nvim-cmp
" cmp-buffer provides a buffer completion source to nvim-cmp
" cmp-path provides a path completion source to nvim-cmp
Plug 'https://github.com/neovim/nvim-lspconfig'
Plug 'https://github.com/hrsh7th/nvim-cmp'
Plug 'https://github.com/L3MON4D3/LuaSnip'
Plug 'https://github.com/hrsh7th/cmp-nvim-lsp'
Plug 'https://github.com/saadparwaiz1/cmp_luasnip'
Plug 'https://github.com/hrsh7th/cmp-buffer'
Plug 'https://github.com/hrsh7th/cmp-path'
" odin for syntax highlighting " odin for syntax highlighting
Plug 'https://github.com/Tetralux/odin.vim' Plug 'https://github.com/Tetralux/odin.vim'
@ -38,35 +22,65 @@ call plug#begin(stdpath('config') . '/plugged')
" Lua cache to speed up load times " Lua cache to speed up load times
Plug 'https://github.com/lewis6991/impatient.nvim' Plug 'https://github.com/lewis6991/impatient.nvim'
" lsp-zero begin
" LSP Support
Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
" Autocompletion
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-nvim-lua'
" Snippets
Plug 'L3MON4D3/LuaSnip'
" Snippet collection (Optional)
Plug 'rafamadriz/friendly-snippets'
Plug 'VonHeikemen/lsp-zero.nvim'
" lsp-zero end
call plug#end() call plug#end()
" Lua Setup " Lua Setup
" ============================================================================== " ==============================================================================
lua <<EOF lua <<EOF
require('impatient') require('impatient')
require('telescope').load_extension('fzf')
require('telescope').setup { -- LSP Setup
defaults = { -- ===========================================================================
layout_config = { local lsp = require('lsp-zero')
horizontal = { width = 0.95 } lsp.preset('recommended')
}, lsp.setup()
mappings = {
i = { -- Treesitter
["<C-j>"] = require('telescope.actions').move_selection_next, -- ===========================================================================
["<C-k>"] = require('telescope.actions').move_selection_previous, -- TODO: 2022-06-19 Treesitter is too slow on large C++ files
}, -- require('nvim-treesitter.configs').setup {
n = { -- ensure_installed = { "c", "cpp" }, -- A list of parser names, or "all"
["<C-j>"] = require('telescope.actions').move_selection_next, -- sync_install = false, -- Install parsers synchronously (only applied to `ensure_installed`)
["<C-k>"] = require('telescope.actions').move_selection_previous, -- ignore_install = { }, -- List of parsers to ignore installing (for "all")
},
}, -- highlight = {
}, -- enable = false, -- `false` will disable the whole extension
pickers = {
find_files = { -- -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
find_command = { "fd", "--unrestricted", "--strip-cwd-prefix" } -- -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
}, -- -- the name of the parser)
} -- -- list of language that will be disabled
} -- disable = { },
-- -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- -- Using this option may slow down your editor, and you may see some duplicate highlights.
-- -- Instead of true it can also be a list of languages
-- additional_vim_regex_highlighting = false,
-- },
-- }
-- Vim Options -- Vim Options
-- =========================================================================== -- ===========================================================================
@ -92,6 +106,7 @@ lua <<EOF
vim.opt.textwidth=80 -- On format, format to 80 char long lines vim.opt.textwidth=80 -- On format, format to 80 char long lines
vim.opt.visualbell=true -- Flash the screen on error vim.opt.visualbell=true -- Flash the screen on error
vim.opt.wrap=false -- Don't wrap lines of text automatically vim.opt.wrap=false -- Don't wrap lines of text automatically
vim.opt.signcolumn = 'no'
vim.diagnostic.config({ vim.diagnostic.config({
-- Turn off the diagnostics signs on the line number. In LSP mode, editing -- Turn off the diagnostics signs on the line number. In LSP mode, editing
@ -106,41 +121,59 @@ lua <<EOF
"", "",
" Useful Bindings (Normal Mode)", " Useful Bindings (Normal Mode)",
" --------------------------------------------------", " --------------------------------------------------",
" <ctrl+n> to open the file tree explorer", " <Ctrl+n> to open the file tree explorer",
" <ctrl+i> clang format selected lines", " <Ctrl+i> clang format selected lines",
" <ctrl+j> jump to next compilation error", " <Ctrl+j> jump to next compilation error",
" <ctrl+k> jump to prev compilation error", " <Ctrl+k> jump to prev compilation error",
" <cd> change working directory to current file", " <cd> change working directory to current file",
" <\\s> split buffer vertically", " <\\s> split buffer vertically",
"", "",
" Abolish Plugin (Text Substitution) (Normal Mode)", " Abolish (Text Substitution in Normal Mode)",
" --------------------------------------------------", " --------------------------------------------------",
" %Subvert/facilit{y,ies}/building{,s}/g Convert facility->building, facilities->buildings", " %S/facilit{y,ies}/building{,s}/g Convert facility->building, facilities->buildings",
" %Subvert/action/sleep/g Convert action to sleep, (preserve case sensitivity ACTION->SLEEP, action->sleep) ", " %S/action/sleep/g Convert action to sleep, (preserve case sensitivity ACTION->SLEEP, action->sleep) ",
"", "",
" Telescope Bindings (Normal Mode)", " FZF (Normal Mode)",
" --------------------------------------------------", " --------------------------------------------------",
" <\\te> open telescope menu", " <\\h> vim command history",
" <\\ta> search for symbol via tags", " <\\f> find files",
" <\\f> search for file", " <\\g> search for text (via ripgrep)",
" <\\g> search for text", " <\\tt> search for tag (global)",
" <\\tb> search for tag (buffer)",
" <\\cc> search for commit (global)",
" <\\cb> search for commit (buffer)",
" <\\b> search for buffer", " <\\b> search for buffer",
" <\\h> search VIM help menu", "",
" Autocompletion (nvim-cmp in Normal Mode)",
" --------------------------------------------------",
" <Enter> Confirms selection.",
" <Ctrl-y> Confirms selection.",
" <Up> Navigate to previous item on the list.",
" <Down> Navigate to the next item on the list.",
" <Ctrl-p> Navigate to previous item on the list.",
" <Ctrl-n> Navigate to the next item on the list.",
" <Ctrl-u> Scroll up in the item's documentation.",
" <Ctrl-f> Scroll down in the item's documentation.",
" <Ctrl-e> Toggles the completion.",
" <Ctrl-d> Go to the next placeholder in the snippet.",
" <Ctrl-b> Go to the previous placeholder in the snippet.",
" <Tab> Enables completion when the cursor is inside a word. If the completion menu is visible it will navigate to the next item in the list.",
" <Shift-Tab> When the completion menu is visible navigate to the previous item in the list.",
"", "",
" LSP Bindings (Normal Mode)", " LSP Bindings (Normal Mode)",
" --------------------------------------------------", " --------------------------------------------------",
" <gD> on (applicable) symbol, jump to declaration", " <Shift-K> Displays hover information about the symbol under the cursor in a floating window. See help vim.lsp.buf.hover().",
" <gd> on (applicable) symbol, jump to definition", " gd Jumps to the definition of the symbol under the cursor. See help vim.lsp.buf.definition().",
" <gt> on (applicable) symbol, jump to type definition", " gD Jumps to the declaration of the symbol under the cursor. Some servers don't implement this feature. See help vim.lsp.buf.declaration().",
" <gr> on (applicable) symbol, show caller references", " gi Lists all the implementations for the symbol under the cursor in the quickfix window. See help vim.lsp.buf.implementation().",
" <gf> on (applicable) symbol, search available symbols", " go Jumps to the definition of the type of the symbol under the cursor. See help vim.lsp.buf.type_definition().",
" <ga> on (applicable) symbol, show code-actions prompt", " gr Lists all the references to the symbol under the cursor in the quickfix window. See help vim.lsp.buf.references().",
" <gR> on (applicable) symbol, code-aware symbol rename", " <Ctrl-k> Displays signature information about the symbol under the cursor in a floating window. See help vim.lsp.buf.signature_help(). If a mapping already exists for this key this function is not bound.",
" <gs> on (applicable) symbol, show signature help", " <F2> Renames all references to the symbol under the cursor. See help vim.lsp.buf.rename().",
" <shift+k> on (applicable) symbol, show documentation", " <F4> Selects a code action available at the current cursor position. See help vim.lsp.buf.code_action().",
" <space+e> on red underlined symbol error, show error message", " gl Show diagnostics in a floating window. See :help vim.diagnostic.open_float().",
" <alt+n> jump to next LSP error", " [d Move to the previous diagnostic in the current buffer. See :help vim.diagnostic.goto_prev().",
" <alt+n> jump to prev LSP error", " ]d Move to the next diagnostic. See :help vim.diagnostic.goto_next()."
} }
local height = vim.api.nvim_get_option("lines") local height = vim.api.nvim_get_option("lines")
@ -159,8 +192,6 @@ lua <<EOF
vim.api.nvim_buf_set_option(buf, "buflisted", true) vim.api.nvim_buf_set_option(buf, "buflisted", true)
end end
-- Only display if there is enough space
if height >= ascii_rows and width >= ascii_cols then
vim.api.nvim_buf_set_lines(buf, 0, -1, false, ascii) vim.api.nvim_buf_set_lines(buf, 0, -1, false, ascii)
vim.api.nvim_buf_set_option(buf, "modified", false) vim.api.nvim_buf_set_option(buf, "modified", false)
vim.api.nvim_buf_set_option(buf, "buflisted", false) vim.api.nvim_buf_set_option(buf, "buflisted", false)
@ -174,125 +205,7 @@ lua <<EOF
callback = reset_start_screen, callback = reset_start_screen,
}) })
end end
end
-- LSP Setup
-- ===========================================================================
-- Load the additional capabilities supported by nvim-cmp
local custom_capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local custom_on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<A-n>', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<A-p>', vim.diagnostic.goto_prev, opts)
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gR', vim.lsp.buf.rename, bufopts)
end
-- Request additional completion capabilities from the LSP server(s)
local lspconfig = require('lspconfig')
-- Clangd LSP Setup
-- ===========================================================================
lspconfig.clangd.setup {
on_attach = custom_on_attach,
capabilities = custom_capabilities,
single_file_support = false, --- Don't launch LSP if the directory does not have LSP metadata
}
lspconfig.cmake.setup {
on_attach = custom_on_attach,
capabilities = custom_capabilities,
}
-- Autocomplete Setup
-- ===========================================================================
local luasnip = require 'luasnip'
local cmp = require 'cmp'
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
cmp.setup {
snippet = {
expand = function(args) luasnip.lsp_expand(args.body) end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
completion = { autocomplete = false },
mapping = cmp.mapping.preset.insert({
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-k>'] = cmp.mapping.scroll_docs(-1), -- Scroll the docs up by 1 line
['<C-j>'] = cmp.mapping.scroll_docs(1), -- Scroll the docs down by 1 line
['<CR>'] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, },
['<Tab>'] = cmp.mapping(function(fallback) -- Move down the autocomplete list
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback) -- Move up the autocomplete list
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
},
}
-- TODO: 2022-06-19 Treesitter is too slow on large C++ files
-- require('nvim-treesitter.configs').setup {
-- ensure_installed = { "c", "cpp" }, -- A list of parser names, or "all"
-- sync_install = false, -- Install parsers synchronously (only applied to `ensure_installed`)
-- ignore_install = { }, -- List of parsers to ignore installing (for "all")
-- highlight = {
-- enable = false, -- `false` will disable the whole extension
-- -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
-- -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
-- -- the name of the parser)
-- -- list of language that will be disabled
-- disable = { },
-- -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- -- Using this option may slow down your editor, and you may see some duplicate highlights.
-- -- Instead of true it can also be a list of languages
-- additional_vim_regex_highlighting = false,
-- },
-- }
EOF EOF
" Theme " Theme
@ -368,17 +281,14 @@ augroup end
" General Key Bindings " General Key Bindings
" ============================================================================== " ==============================================================================
" Telescope Bindings " Telescope Bindings
nnoremap <leader>f <cmd>Telescope find_files<cr> nnoremap <leader>h <cmd>FzfHistory<cr>
nnoremap <leader>g <cmd>Telescope live_grep<cr> nnoremap <leader>f <cmd>FzfFiles<cr>
nnoremap <leader>ta <cmd>Telescope tags<cr> nnoremap <leader>g <cmd>FzfRg<cr>
nnoremap <leader>te <cmd>Telescope<cr> nnoremap <leader>tt <cmd>FzfTags<cr>
nnoremap <leader>b <cmd>Telescope buffers<cr> nnoremap <leader>tb <cmd>FzfBTags<cr>
nnoremap <leader>h <cmd>Telescope help_tags<cr> nnoremap <leader>cc <cmd>FzfCommits<cr>
nnoremap <leader>cb <cmd>FzfBCommits<cr>
nnoremap gf <cmd>Telescope lsp_dynamic_workspace_symbols<cr> nnoremap <leader>b <cmd>FzfBuffers<cr>
nnoremap gd <cmd>Telescope lsp_definitions<cr>
nnoremap gt <cmd>Telescope lsp_type_definitions<cr>
nnoremap gr <cmd>Telescope lsp_references<cr>
" Map Ctrl+HJKL to navigate buffer window " Map Ctrl+HJKL to navigate buffer window
nmap <silent> <C-h> :wincmd h<CR> nmap <silent> <C-h> :wincmd h<CR>