Last active
February 1, 2022 03:11
-
-
Save Desdaemon/a6aa59cea391bb742721d008f7a48fed to your computer and use it in GitHub Desktop.
NVIM config file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Full list at https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md | |
local servers = { | |
'pyright', 'rust_analyzer', 'tsserver', 'dartls', 'clangd', | |
-- Provided by vscode-langservers-extracted | |
'html', 'eslint', 'cssls', 'jsonls', | |
} | |
local use = require('packer').use | |
require('packer').startup(function() | |
use 'wbthomason/packer.nvim' -- Self-management | |
use 'ayu-theme/ayu-vim' | |
use 'scrooloose/nerdtree' | |
use 'scrooloose/nerdcommenter' | |
use 'tpope/vim-surround' | |
use 'tpope/vim-repeat' | |
use 'easymotion/vim-easymotion' | |
use 'vim-airline/vim-airline' | |
use 'editorconfig/editorconfig-vim' | |
use 'jiangmiao/auto-pairs' | |
use 'airblade/vim-gitgutter' | |
use 'junegunn/fzf' | |
use 'neovim/nvim-lspconfig' -- Collection of configurations for built-in LSP client | |
use 'hrsh7th/nvim-cmp' -- Autocompletion plugin | |
use 'hrsh7th/cmp-nvim-lsp' -- LSP source for nvim-cmp | |
use 'saadparwaiz1/cmp_luasnip' -- Snippets source for nvim-cmp | |
use 'L3MON4D3/LuaSnip' -- Snippets plugin | |
use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'} | |
use {'yuki-yano/fzf-preview.vim', branch = 'release/rpc'} | |
end) | |
vim.g.mapleader = ',' | |
vim.g.airline_powerline_fonts = 1 | |
vim.g.NERDSpaceDelims = 1 | |
vim.opt.mouse = 'a' | |
vim.opt.termguicolors = true | |
vim.opt.number = true | |
vim.opt.hlsearch = true | |
vim.opt.incsearch = true | |
vim.opt.encoding = 'utf-8' | |
-- TextEdit might fail if hidden is not set. | |
vim.opt.hidden = true | |
-- Some servers have issues with backup files. | |
vim.opt.backup = false | |
vim.opt.writebackup = false | |
-- Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable | |
-- delays and poor user experience. | |
vim.opt.updatetime = 300 | |
vim.opt.expandtab = true | |
vim.opt.shiftwidth = 4 | |
vim.opt.tabstop = 4 | |
vim.g.ayucolor = 'dark' | |
vim.cmd 'colorscheme ayu' | |
vim.cmd "hi Normal guibg=NONE ctermbg=NONE" | |
-- Always show the signcolumn, otherwise it would shift the text each time | |
-- diagnostics appear/become resolved. | |
if vim.fn.has('nvim-0.5.0') == 1 or vim.fn.has('patch-8.1.1564') == 1 then | |
vim.opt.signcolumn = 'number' | |
else | |
-- Recently vim can merge signcolumn and number column into one | |
vim.opt.signcoumn = 'yes' | |
end | |
local opts = { noremap=true, silent=true } | |
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts) | |
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts) | |
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts) | |
-- Use an on_attach function to only map the following keys | |
-- after the language server attaches to the current buffer | |
local 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') | |
-- Mappings. | |
-- See `:help vim.lsp.*` for documentation on any of the below functions | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) | |
end | |
require'nvim-treesitter.configs'.setup { | |
-- One of "all", "maintained" (parsers with maintainers), or a list of languages | |
ensure_installed = "maintained", | |
-- Install languages synchronously (only applied to `ensure_installed`) | |
sync_install = false, | |
-- List of parsers to ignore installing | |
-- ignore_install = { "javascript" }, | |
highlight = { | |
-- `false` will disable the whole extension | |
enable = true, | |
-- list of language that will be disabled | |
-- disable = { "c", "rust" }, | |
-- 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, | |
}, | |
} | |
-- LSP config | |
-- Add additional capabilities supported by nvim-cmp | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) | |
capabilities.textDocument.completion.completionItem.snippetSupport = true | |
local lspconfig = require('lspconfig') | |
-- Use a loop to conveniently call 'setup' on multiple servers and | |
-- map buffer local keybindings when the language server attaches | |
for _, lsp in pairs(servers) do | |
require('lspconfig')[lsp].setup { | |
on_attach = on_attach, | |
capabilities = capabilities, | |
flags = { | |
-- This will be the default in neovim 0.7+ | |
debounce_text_changes = 150, | |
} | |
} | |
end | |
-- luasnip setup | |
local luasnip = require 'luasnip' | |
-- nvim-cmp setup | |
local cmp = require 'cmp' | |
cmp.setup { | |
snippet = { | |
expand = function(args) | |
require('luasnip').lsp_expand(args.body) | |
end, | |
}, | |
mapping = { | |
['<C-p>'] = cmp.mapping.select_prev_item(), | |
['<C-n>'] = cmp.mapping.select_next_item(), | |
['<C-d>'] = cmp.mapping.scroll_docs(-4), | |
['<C-f>'] = cmp.mapping.scroll_docs(4), | |
['<C-Space>'] = cmp.mapping.complete(), | |
['<C-e>'] = cmp.mapping.close(), | |
['<CR>'] = cmp.mapping.confirm { | |
behavior = cmp.ConfirmBehavior.Replace, | |
select = true, | |
}, | |
['<Tab>'] = function(fallback) | |
if cmp.visible() then | |
cmp.select_next_item() | |
elseif luasnip.expand_or_jumpable() then | |
luasnip.expand_or_jump() | |
else | |
fallback() | |
end | |
end, | |
['<S-Tab>'] = function(fallback) | |
if cmp.visible() then | |
cmp.select_prev_item() | |
elseif luasnip.jumpable(-1) then | |
luasnip.jump(-1) | |
else | |
fallback() | |
end | |
end, | |
}, | |
sources = { | |
{ name = 'nvim_lsp' }, | |
{ name = 'luasnip' }, | |
}, | |
} | |
vim.cmd [[ | |
nmap <Leader>f [fzf-p] | |
xmap <Leader>f [fzf-p] | |
]] | |
vim.api.nvim_set_keymap('n', '[fzf-p]p', ':<C-u>FzfPreviewFromResourcesRpc project_mru git<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]b', ':<C-u>FzfPreviewBuffersRpc<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]B', ':<C-u>FzfPreviewAllBuffersRpc<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]o', ':<C-u>FzfPreviewFromResourcesRpc buffer project_mru<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]/', ':<C-u>FzfPreviewLinesRpc --add-fzf-arg=--no-sort --add-fzf-arg=--query=""<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]*', ':<C-u>FzfPreviewLinesRpc --add-fzf-arg=--no-sort --add-fzf-arg=--query="<C-r>=expand(\'<cword>\')<CR>"<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]t', ':<C-u>FzfPreviewBufferTagsRpc<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]q', ':<C-u>FzfPreviewQuickFixRpc<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]l', ':<C-u>FzfPreviewLocationListRpc<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]g;', ':<C-u>FzfPreviewChangesRpc<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]gs', ':<C-u>FzfPreviewGitStatusRpc<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]ga', ':<C-u>FzfPreviewGitActionsRpc<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]gr', ':<C-u>FzfPreviewProjectGrepRpc<Space>', opts) | |
vim.api.nvim_set_keymap('x', '[fzf-p]gr', "\"sy:FzfPreviewProjectGrepRpc<Space>-F<Space>\"<C-r>=substitute(substitute(@s, '\n', '', 'g'), '/', '\\/', 'g')<CR>\"", opts) | |
vim.api.nvim_set_keymap('n', '[fzf-p]<C-o>', ':<C-u>FzfPreviewJumpsRpc<CR>', opts) | |
-- vim:expandtab:ts=2:sw=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment