nvim: Remove telescope, use fzf directly
This commit is contained in:
parent
e0a3120a03
commit
afd77e38e9
@ -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 <<EOF
|
||||
require('impatient')
|
||||
require('telescope').load_extension('fzf')
|
||||
require('telescope').setup {
|
||||
defaults = {
|
||||
layout_config = {
|
||||
horizontal = { width = 0.95 }
|
||||
},
|
||||
mappings = {
|
||||
i = {
|
||||
["<C-j>"] = require('telescope.actions').move_selection_next,
|
||||
["<C-k>"] = require('telescope.actions').move_selection_previous,
|
||||
},
|
||||
n = {
|
||||
["<C-j>"] = require('telescope.actions').move_selection_next,
|
||||
["<C-k>"] = 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 <<EOF
|
||||
vim.opt.textwidth=80 -- On format, format to 80 char long lines
|
||||
vim.opt.visualbell=true -- Flash the screen on error
|
||||
vim.opt.wrap=false -- Don't wrap lines of text automatically
|
||||
vim.opt.signcolumn = 'no'
|
||||
|
||||
vim.diagnostic.config({
|
||||
-- Turn off the diagnostics signs on the line number. In LSP mode, editing
|
||||
@ -106,41 +121,59 @@ lua <<EOF
|
||||
"",
|
||||
" Useful Bindings (Normal Mode)",
|
||||
" --------------------------------------------------",
|
||||
" <ctrl+n> to open the file tree explorer",
|
||||
" <ctrl+i> clang format selected lines",
|
||||
" <ctrl+j> jump to next compilation error",
|
||||
" <ctrl+k> jump to prev compilation error",
|
||||
" <cd> change working directory to current file",
|
||||
" <\\s> split buffer vertically",
|
||||
" <Ctrl+n> to open the file tree explorer",
|
||||
" <Ctrl+i> clang format selected lines",
|
||||
" <Ctrl+j> jump to next compilation error",
|
||||
" <Ctrl+k> jump to prev compilation error",
|
||||
" <cd> 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)",
|
||||
" --------------------------------------------------",
|
||||
" <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)",
|
||||
" --------------------------------------------------",
|
||||
" <gD> on (applicable) symbol, jump to declaration",
|
||||
" <gd> on (applicable) symbol, jump to definition",
|
||||
" <gt> on (applicable) symbol, jump to type definition",
|
||||
" <gr> on (applicable) symbol, show caller references",
|
||||
" <gf> on (applicable) symbol, search available symbols",
|
||||
" <ga> on (applicable) symbol, show code-actions prompt",
|
||||
" <gR> on (applicable) symbol, code-aware symbol rename",
|
||||
" <gs> on (applicable) symbol, show signature help",
|
||||
" <shift+k> on (applicable) symbol, show documentation",
|
||||
" <space+e> on red underlined symbol error, show error message",
|
||||
" <alt+n> jump to next LSP error",
|
||||
" <alt+n> jump to prev LSP error",
|
||||
" <Shift-K> 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().",
|
||||
" <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.",
|
||||
" <F2> Renames all references to the symbol under the cursor. See help vim.lsp.buf.rename().",
|
||||
" <F4> 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 <<EOF
|
||||
vim.api.nvim_buf_set_option(buf, "buflisted", true)
|
||||
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_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 = "<buffer>",
|
||||
callback = reset_start_screen,
|
||||
})
|
||||
end
|
||||
vim.api.nvim_create_autocmd("InsertEnter,WinEnter", {
|
||||
pattern = "<buffer>",
|
||||
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 <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
|
||||
|
||||
" Theme
|
||||
@ -368,17 +281,14 @@ augroup end
|
||||
" General Key Bindings
|
||||
" ==============================================================================
|
||||
" Telescope Bindings
|
||||
nnoremap <leader>f <cmd>Telescope find_files<cr>
|
||||
nnoremap <leader>g <cmd>Telescope live_grep<cr>
|
||||
nnoremap <leader>ta <cmd>Telescope tags<cr>
|
||||
nnoremap <leader>te <cmd>Telescope<cr>
|
||||
nnoremap <leader>b <cmd>Telescope buffers<cr>
|
||||
nnoremap <leader>h <cmd>Telescope help_tags<cr>
|
||||
|
||||
nnoremap gf <cmd>Telescope lsp_dynamic_workspace_symbols<cr>
|
||||
nnoremap gd <cmd>Telescope lsp_definitions<cr>
|
||||
nnoremap gt <cmd>Telescope lsp_type_definitions<cr>
|
||||
nnoremap gr <cmd>Telescope lsp_references<cr>
|
||||
nnoremap <leader>h <cmd>FzfHistory<cr>
|
||||
nnoremap <leader>f <cmd>FzfFiles<cr>
|
||||
nnoremap <leader>g <cmd>FzfRg<cr>
|
||||
nnoremap <leader>tt <cmd>FzfTags<cr>
|
||||
nnoremap <leader>tb <cmd>FzfBTags<cr>
|
||||
nnoremap <leader>cc <cmd>FzfCommits<cr>
|
||||
nnoremap <leader>cb <cmd>FzfBCommits<cr>
|
||||
nnoremap <leader>b <cmd>FzfBuffers<cr>
|
||||
|
||||
" Map Ctrl+HJKL to navigate buffer window
|
||||
nmap <silent> <C-h> :wincmd h<CR>
|
||||
|
Loading…
Reference in New Issue
Block a user