From afd77e38e9501adf977e65aa0a01ee274f30986f Mon Sep 17 00:00:00 2001 From: doyle Date: Thu, 5 Jan 2023 12:05:48 +1100 Subject: [PATCH] nvim: Remove telescope, use fzf directly --- Installer/os_nvim_init.vim | 334 ++++++++++++++----------------------- 1 file changed, 122 insertions(+), 212 deletions(-) diff --git a/Installer/os_nvim_init.vim b/Installer/os_nvim_init.vim index ad65f05..71d835c 100644 --- a/Installer/os_nvim_init.vim +++ b/Installer/os_nvim_init.vim @@ -12,25 +12,9 @@ call plug#begin(stdpath('config') . '/plugged') " Plug 'https://github.com/nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} Plug 'https://github.com/bfrg/vim-cpp-modern' - " Telescope file picker, sorter and previewer - Plug 'https://github.com/nvim-lua/plenary.nvim' - Plug 'https://github.com/nvim-telescope/telescope.nvim' - 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' + " FZF + Plug 'junegunn/fzf' + Plug 'junegunn/fzf.vim' " odin for syntax highlighting Plug 'https://github.com/Tetralux/odin.vim' @@ -38,35 +22,65 @@ call plug#begin(stdpath('config') . '/plugged') " Lua cache to speed up load times 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() " Lua Setup " ============================================================================== lua <"] = require('telescope.actions').move_selection_next, - [""] = require('telescope.actions').move_selection_previous, - }, - n = { - [""] = require('telescope.actions').move_selection_next, - [""] = require('telescope.actions').move_selection_previous, - }, - }, - }, - pickers = { - find_files = { - find_command = { "fd", "--unrestricted", "--strip-cwd-prefix" } - }, - } - } + + -- LSP Setup + -- =========================================================================== + local lsp = require('lsp-zero') + lsp.preset('recommended') + lsp.setup() + + -- Treesitter + -- =========================================================================== + -- 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, + -- }, + -- } -- Vim Options -- =========================================================================== @@ -92,6 +106,7 @@ lua < to open the file tree explorer", - " clang format selected lines", - " jump to next compilation error", - " jump to prev compilation error", - " change working directory to current file", - " <\\s> split buffer vertically", + " to open the file tree explorer", + " clang format selected lines", + " jump to next compilation error", + " jump to prev compilation error", + " change working directory to current file", + " <\\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", - " %Subvert/action/sleep/g Convert action to sleep, (preserve case sensitivity ACTION->SLEEP, action->sleep) ", + " %S/facilit{y,ies}/building{,s}/g Convert facility->building, facilities->buildings", + " %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", - " <\\ta> search for symbol via tags", - " <\\f> search for file", - " <\\g> search for text", - " <\\b> search for buffer", - " <\\h> search VIM help menu", + " <\\h> vim command history", + " <\\f> find files", + " <\\g> search for text (via ripgrep)", + " <\\tt> search for tag (global)", + " <\\tb> search for tag (buffer)", + " <\\cc> search for commit (global)", + " <\\cb> search for commit (buffer)", + " <\\b> search for buffer", + "", + " Autocompletion (nvim-cmp in Normal Mode)", + " --------------------------------------------------", + " Confirms selection.", + " Confirms selection.", + " Navigate to previous item on the list.", + " Navigate to the next item on the list.", + " Navigate to previous item on the list.", + " Navigate to the next item on the list.", + " Scroll up in the item's documentation.", + " Scroll down in the item's documentation.", + " Toggles the completion.", + " Go to the next placeholder in the snippet.", + " Go to the previous placeholder in the snippet.", + " 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.", + " When the completion menu is visible navigate to the previous item in the list.", "", " LSP Bindings (Normal Mode)", " --------------------------------------------------", - " on (applicable) symbol, jump to declaration", - " on (applicable) symbol, jump to definition", - " on (applicable) symbol, jump to type definition", - " on (applicable) symbol, show caller references", - " on (applicable) symbol, search available symbols", - " on (applicable) symbol, show code-actions prompt", - " on (applicable) symbol, code-aware symbol rename", - " on (applicable) symbol, show signature help", - " on (applicable) symbol, show documentation", - " on red underlined symbol error, show error message", - " jump to next LSP error", - " jump to prev LSP error", + " Displays hover information about the symbol under the cursor in a floating window. See help vim.lsp.buf.hover().", + " gd Jumps to the definition of the symbol under the cursor. See help vim.lsp.buf.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().", + " gi Lists all the implementations for the symbol under the cursor in the quickfix window. See help vim.lsp.buf.implementation().", + " go Jumps to the definition of the type of the symbol under the cursor. See help vim.lsp.buf.type_definition().", + " gr Lists all the references to the symbol under the cursor in the quickfix window. See help vim.lsp.buf.references().", + " 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.", + " Renames all references to the symbol under the cursor. See help vim.lsp.buf.rename().", + " Selects a code action available at the current cursor position. See help vim.lsp.buf.code_action().", + " gl Show diagnostics in a floating window. See :help vim.diagnostic.open_float().", + " [d Move to the previous diagnostic in the current buffer. See :help vim.diagnostic.goto_prev().", + " ]d Move to the next diagnostic. See :help vim.diagnostic.goto_next()." } local height = vim.api.nvim_get_option("lines") @@ -159,140 +192,20 @@ lua <= ascii_rows and width >= ascii_cols then - 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, "buflisted", false) - vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe") - vim.api.nvim_buf_set_option(buf, "buftype", "nofile") - vim.api.nvim_buf_set_option(buf, "swapfile", false) - vim.api.nvim_set_current_buf(buf) + 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, "buflisted", false) + vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe") + vim.api.nvim_buf_set_option(buf, "buftype", "nofile") + vim.api.nvim_buf_set_option(buf, "swapfile", false) + vim.api.nvim_set_current_buf(buf) - vim.api.nvim_create_autocmd("InsertEnter,WinEnter", { - pattern = "", - callback = reset_start_screen, - }) - end + vim.api.nvim_create_autocmd("InsertEnter,WinEnter", { + pattern = "", + callback = reset_start_screen, + }) 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 - 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', 'e', vim.diagnostic.open_float, opts) - vim.keymap.set('n', '', vim.diagnostic.goto_next, opts) - vim.keymap.set('n', '', 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({ - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(-1), -- Scroll the docs up by 1 line - [''] = cmp.mapping.scroll_docs(1), -- Scroll the docs down by 1 line - [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, - [''] = 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' }), - [''] = 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 " Theme @@ -368,17 +281,14 @@ augroup end " General Key Bindings " ============================================================================== " Telescope Bindings -nnoremap f Telescope find_files -nnoremap g Telescope live_grep -nnoremap ta Telescope tags -nnoremap te Telescope -nnoremap b Telescope buffers -nnoremap h Telescope help_tags - -nnoremap gf Telescope lsp_dynamic_workspace_symbols -nnoremap gd Telescope lsp_definitions -nnoremap gt Telescope lsp_type_definitions -nnoremap gr Telescope lsp_references +nnoremap h FzfHistory +nnoremap f FzfFiles +nnoremap g FzfRg +nnoremap tt FzfTags +nnoremap tb FzfBTags +nnoremap cc FzfCommits +nnoremap cb FzfBCommits +nnoremap b FzfBuffers " Map Ctrl+HJKL to navigate buffer window nmap :wincmd h