From a317a0e85f2a3ca8bb0d043c81fc865c0eeb901e Mon Sep 17 00:00:00 2001 From: Anish L Date: Sat, 26 Feb 2022 03:32:15 +1000 Subject: [PATCH] modernizing my nvim config. uses a lot of lua now, and also cmp,lspconfig,bufferline --- profiles/nvim/nvim.nix | 628 ++++++++++++++++++++++++++++++----------- 1 file changed, 470 insertions(+), 158 deletions(-) diff --git a/profiles/nvim/nvim.nix b/profiles/nvim/nvim.nix index a96514f9..ccb0c14c 100644 --- a/profiles/nvim/nvim.nix +++ b/profiles/nvim/nvim.nix @@ -37,9 +37,10 @@ let tasklib pynvim six - #pyls-mypy - #pyls-isort - #pyls-black + python-lsp-server + pylsp-mypy + python-lsp-black + pylint # other python packages you want ]; python-with-my-packages = pkgs.python3.withPackages my-python-packages; @@ -55,10 +56,9 @@ in python-with-my-packages clojure-lsp rnix-lsp - #python3Packages.pynvim - #python3Packages.six - #python3Packages.tasklib - #python3 + terraform-lsp + nodePackages.typescript-lsp-server + # Other LSPs ( neovim.override { vimAlias = true; withPython3 = true; @@ -71,38 +71,46 @@ in vim-elixir emmet-vim nerdtree + ayu-vim goyo-vim vim-sneak - lightline-vim csv-vim - vimwiki - coc-nvim - coc-json - ale - coc-pyright - coc-pairs - coc-emmet - LanguageClient-neovim - ayu-vim rainbow_parentheses-vim vim-surround - vim-fugitive - vim-signify - fzf-checkout-vim - #nvim-colorizer + bufferline-nvim + feline-nvim + nvim-webdev-icons vim-devicons - # testing - #vim-processing - #vim-tidal + # kitaab stuff + vimwiki taskwiki vim-zettel - #vimwiki-sync telescope-nvim plenary-nvim + # lsp stuff + ale + black-vim + nvim-lspconfig + nvim-cmp + nvim-cmp-lsp + nvim-lsp-ts-utils + cmp-conjure + cmp-buffer + cmp-tabnine + lspkind-nvim + luasnip + cmp_luasnip + # git stuff + vim-fugitive + gitsigns-nvim + fzf-checkout-vim # Clojure stuff conjure vim-sexp vim-sexp-mappings-for-regular-people + # testing + #vim-processing + #vim-tidal ]; }; @@ -112,6 +120,7 @@ in set shiftwidth=2 set noexpandtab set autoindent + set undofile " set foldmethod=indent " fold based on indent set number @@ -143,11 +152,6 @@ in let mapleader = "\" let maplocalleader = "," - " lightline colorscheme - let g:lightline = { - \ 'colorscheme': 'seoul256', - \ } - " moving splits with vim movements. :tnoremap h :tnoremap j @@ -171,15 +175,9 @@ in nnoremap fb Telescope buffers nnoremap fh Telescope help_tags - " exit normal mode in terminal :tnoremap - let g:syntastic_always_populate_loc_list = 1 - let g:syntastic_auto_loc_list = 1 - let g:syntastic_check_on_open = 1 - let g:syntastic_check_on_wq = 0 - " Sexp in Conjure (since it's fennel) " let g:sexp_filetypes = [ "fennel" ] @@ -215,6 +213,10 @@ in inoremap :m .-2== nnoremap j :m .+1== nnoremap k :m .-2== + " Pasting + :map sy :!xclip -i + :vmap sy "*y + :map sp :r!xclip -o " git nmap gd :SignifyDiff @@ -238,13 +240,8 @@ in " fzf let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } } - " ALE + clj-kondo - let g:ale_linters = {'clojure': ['clj-kondo']} - - " coc - " conjure extension - let g:coc_global_extensions = ['coc-conjure'] + let g:ale_linters = {'clojure': ['clj-kondo'], 'python': ['black', 'pylint']} " if hidden is not set, TextEdit might fail. set hidden @@ -265,129 +262,444 @@ in " always show signcolumns set signcolumn=yes - " note that if you are using Plug mapping you should not use `noremap` mappings. - nmap (lcn-menu) - " Or map each action separately - nmap K (lcn-hover) - nmap gd (lcn-definition) - nmap (lcn-r - " Use tab for trigger completion with characters ahead and navigate. - " Use command ':verbose imap ' to make sure tab is not mapped by other plugin. - inoremap - \ pumvisible() ? "\" : - \ check_back_space() ? "\" : - \ coc#refresh() - inoremap pumvisible() ? "\" : "\" + " lsp commands + nnoremap vd :lua vim.lsp.buf.definition() + nnoremap vi :lua vim.lsp.buf.implementation() + nnoremap vsh :lua vim.lsp.buf.signature_help() + nnoremap vrr :lua vim.lsp.buf.references() + nnoremap vrn :lua vim.lsp.buf.rename() + nnoremap vh :lua vim.lsp.buf.hover() + nnoremap vca :lua vim.lsp.buf.code_action() + nnoremap vsd :lua vim.lsp.diagnostic.show_line_diagnostics(); vim.lsp.util.show_line_diagnostics() + nnoremap vn :lua vim.lsp.diagnostic.goto_next() + nnoremap vll :call LspLocationList() + augroup THE_PRIMEAGEN_LSP + autocmd! + autocmd! BufWrite,BufEnter,InsertLeave * :call LspLocationList() + augroup END - function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' - endfunction + "bufferline + " These commands will navigate through buffers in order regardless of which mode you are using + nnoremap [b :BufferLineCycleNext + nnoremap b] :BufferLineCyclePrev - " Use to trigger completion. - inoremap coc#refresh() + " lua config + lua < to confirm completion, `u` means break undo chain at current position. - " Coc only does snippet and additional edit on confirm. - inoremap pumvisible() ? "\" : "\u\" - " Or use `complete_info` if your vim support it, like: - " inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" + -- Setup nvim-cmp. + local cmp = require'cmp' + cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, + formatting = { + format = function(entry, vim_item) + local icons = require "plugins.configs.lspkind_icons" + vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) + vim_item.menu = ({ + nvim_lsp = "[LSP]", + clojure_lsp = "[CLJ]", + buffer = "[BUF]", + terraform_lsp = "[TER]", + pylsp = "[PY]", + rnix-lsp = "[NIX]", + })[entry.source.name] + return vim_item + end, + }, + mapping = { + [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [''] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, -- For luasnip users. + }, { + { name = 'buffer' }, + }) + }) + -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + { name = "nvim_lsp"}, + { name = "path" }, + { name = 'conjure'}, + { name = 'cmp_tabnine'}, + } + }) + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) - " Use `[g` and `]g` to navigate diagnostics - nmap [g (coc-diagnostic-prev) - nmap ]g (coc-diagnostic-next) + -- Setup lspconfig. + local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + require('lspconfig')['nvim_lsp', clojure_lsp', 'rnix-lsp', 'pylsp', 'terraform_lsp', 'tsserver'].setup { + capabilities = capabilities + } - " Remap keys for gotos - nmap gd (coc-definition) - nmap gy (coc-type-definition) - nmap gi (coc-implementation) - nmap gr (coc-references) + -- Feline + local colors = require 'theme.colors' + local lsp = require 'feline.providers.lsp' + local vi_mode_utils = require 'feline.providers.vi_mode' + local vi_mode_colors = { + NORMAL = colors.green, + INSERT = colors.red, + VISUAL = colors.magenta, + OP = colors.green, + BLOCK = colors.blue, + REPLACE = colors.violet, + ['V-REPLACE'] = colors.violet, + ENTER = colors.cyan, + MORE = colors.cyan, + SELECT = colors.orange, + COMMAND = colors.green, + SHELL = colors.green, + TERM = colors.green, + NONE = colors.yellow + } + local icons = { + linux = ' ', + macos = ' ', + windows = ' ', + errs = ' ', + warns = ' ', + infos = ' ', + hints = ' ', + lsp = ' ', + git = '' + } + local function file_osinfo() + local os = vim.bo.fileformat:upper() + local icon + if os == 'UNIX' then + icon = icons.linux + elseif os == 'MAC' then + icon = icons.macos + else + icon = icons.windows + end + return icon .. os + end + local function lsp_diagnostics_info() + return { + errs = lsp.get_diagnostics_count('Error'), + warns = lsp.get_diagnostics_count('Warning'), + infos = lsp.get_diagnostics_count('Information'), + hints = lsp.get_diagnostics_count('Hint') + } + end + local function diag_enable(f, s) + return function() + local diag = f()[s] + return diag and diag ~= 0 + end + end + local function diag_of(f, s) + local icon = icons[s] + return function() + local diag = f()[s] + return icon .. diag + end + end + local function vimode_hl() + return { + name = vi_mode_utils.get_mode_highlight_name(), + fg = vi_mode_utils.get_mode_color() + } + end + -- LuaFormatter off + local comps = { + vi_mode = { + left = { + provider = '▊', + hl = vimode_hl, + right_sep = ' ' + }, + right = { + provider = '▊', + hl = vimode_hl, + left_sep = ' ' + } + }, + file = { + info = { + provider = 'file_info', + hl = { + fg = colors.blue, + style = 'bold' + } + }, + encoding = { + provider = 'file_encoding', + left_sep = ' ', + hl = { + fg = colors.violet, + style = 'bold' + } + }, + type = { + provider = 'file_type' + }, + os = { + provider = file_osinfo, + left_sep = ' ', + hl = { + fg = colors.violet, + style = 'bold' + } + } + }, + line_percentage = { + provider = 'line_percentage', + left_sep = ' ', + hl = { + style = 'bold' + } + }, + scroll_bar = { + provider = 'scroll_bar', + left_sep = ' ', + hl = { + fg = colors.blue, + style = 'bold' + } + }, + diagnos = { + err = { + provider = diag_of(lsp_diagnostics_info, 'errs'), + left_sep = ' ', + enabled = diag_enable(lsp_diagnostics_info, 'errs'), + hl = { + fg = colors.red + } + }, + warn = { + provider = diag_of(lsp_diagnostics_info, 'warns'), + left_sep = ' ', + enabled = diag_enable(lsp_diagnostics_info, 'warns'), + hl = { + fg = colors.yellow + } + }, + info = { + provider = diag_of(lsp_diagnostics_info, 'infos'), + left_sep = ' ', + enabled = diag_enable(lsp_diagnostics_info, 'infos'), + hl = { + fg = colors.blue + } + }, + hint = { + provider = diag_of(lsp_diagnostics_info, 'hints'), + left_sep = ' ', + enabled = diag_enable(lsp_diagnostics_info, 'hints'), + hl = { + fg = colors.cyan + } + }, + }, + lsp = { + name = { + provider = 'lsp_client_names', + left_sep = ' ', + icon = icons.lsp, + hl = { + fg = colors.yellow + } + } + }, + git = { + branch = { + provider = 'git_branch', + icon = icons.git, + left_sep = ' ', + hl = { + fg = colors.violet, + style = 'bold' + }, + }, + add = { + provider = 'git_diff_added', + hl = { + fg = colors.green + } + }, + change = { + provider = 'git_diff_changed', + hl = { + fg = colors.orange + } + }, + remove = { + provider = 'git_diff_removed', + hl = { + fg = colors.red + } + } + } + } + local properties = { + force_inactive = { + filetypes = { + 'NvimTree', + 'dbui', + 'packer', + 'startify', + 'fugitive', + 'fugitiveblame' + }, + buftypes = {'terminal'}, + bufnames = {} + } + } + local components = { + left = { + active = { + comps.vi_mode.left, + comps.file.info, + comps.lsp.name, + comps.diagnos.err, + comps.diagnos.warn, + comps.diagnos.hint, + comps.diagnos.info + }, + inactive = { + comps.vi_mode.left, + comps.file.info + } + }, + mid = { + active = {}, + inactive = {} + }, + right = { + active = { + comps.git.add, + comps.git.change, + comps.git.remove, + comps.file.os, + comps.git.branch, + comps.line_percentage, + comps.scroll_bar, + comps.vi_mode.right + }, + inactive = {} + } + } + -- LuaFormatter on + require'feline'.setup { + default_bg = colors.bg, + default_fg = colors.fg, + components = components, + properties = properties, + vi_mode_colors = vi_mode_colors + } - " Use K to show documentation in preview window - nnoremap K :call show_documentation() - - function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - else - call CocAction('doHover') - endif - endfunction - - " Highlight symbol under cursor on CursorHold - autocmd CursorHold * silent call CocActionAsync('highlight') - - " Remap for rename current word - nmap rn (coc-rename) - - " Remap for format selected region - xmap f (coc-format-selected) - nmap f (coc-format-selected) - - augroup mygroup - autocmd! - " Setup formatexpr specified filetype(s). - autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') - " Update signature help on jump placeholder - autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') - augroup end - - " Remap for do codeAction of selected region, ex: `aap` for current paragraph - xmap a (coc-codeaction-selected) - nmap a (coc-codeaction-selected) - - " Remap for do codeAction of current line - nmap ac (coc-codeaction) - " Fix autofix problem of current line - nmap qf (coc-fix-current) - - " Create mappings for function text object, requires document symbols feature of languageserver. - xmap if (coc-funcobj-i) - xmap af (coc-funcobj-a) - omap if (coc-funcobj-i) - omap af (coc-funcobj-a) - - " Use for select selections ranges, needs server support, like: coc-tsserver, coc-python - nmap (coc-range-select) - xmap (coc-range-select) - - " Use `:Format` to format current buffer - command! -nargs=0 Format :call CocAction('format') - - " Use `:Fold` to fold current buffer - command! -nargs=? Fold :call CocAction('fold', ) - - " use `:OR` for organize import of current buffer - command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') - - " Add status line support, for integration with other plugin, checkout `:h coc-status` - " set statusline^=%{coc#status()}%{get(b:,'coc_current_function',"")} - - " Using CocList - " Show all diagnostics - nnoremap a :CocList diagnostics - " Manage extensions - nnoremap e :CocList extensions - " Show commands - nnoremap c :CocList commands - " Find symbol of current document - nnoremap o :CocList outline - " Search workspace symbols - nnoremap s :CocList -I symbols - " Do default action for next item. - nnoremap j :CocNext - " Do default action for previous item. - nnoremap k :CocPrev - " Resume latest coc list - nnoremap p :CocListResume - - au BufNewFile,BufRead *.frag,*.vert,*.fp,*.vp,*.glsl setf glsl - - " TODO Ugly map - :map :!xclip -i - :vmap "*y - :map :r!xclip -o + -- Buffeline + require('bufferline').setup { + options = { + numbers = "ordinal", + --- @deprecated, please specify numbers as a function to customize the styling + number_style = "superscript", + close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = "bdelete! %d", -- can be a string | function, see "Mouse actions" + left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + -- NOTE: this plugin is designed with this icon in mind, + -- and so changing this is NOT recommended, this is intended + -- as an escape hatch for people who cannot bear it for whatever reason + indicator_icon = '▎', + buffer_close_icon = '', + modified_icon = '●', + close_icon = '', + left_trunc_marker = '', + right_trunc_marker = '', + --- name_formatter can be used to change the buffer's label in the bufferline. + --- Please note some names can/will break the + --- bufferline so use this at your discretion knowing that it has + --- some limitations that will *NOT* be fixed. + name_formatter = function(buf) -- buf contains a "name", "path" and "bufnr" + -- remove extension from markdown files for example + if buf.name:match('%.md') then + return vim.fn.fnamemodify(buf.name, ':t:r') + end + end, + max_name_length = 18, + max_prefix_length = 15, -- prefix used when a buffer is de-duplicated + tab_size = 18, + diagnostics = "nvim_lsp", + diagnostics_update_in_insert = false, + diagnostics_indicator = function(count, level, diagnostics_dict, context) + return "("..count..")" + end, + -- NOTE: this will be called a lot so don't do any heavy processing here + custom_filter = function(buf_number, buf_numbers) + -- filter out filetypes you don't want to see + if vim.bo[buf_number].filetype ~= "" then + return true + end + -- filter out by buffer name + if vim.fn.bufname(buf_number) ~= "" then + return true + end + -- filter out based on arbitrary rules + -- e.g. filter out vim wiki buffer from tabline in your work repo + if vim.fn.getcwd() == "" and vim.bo[buf_number].filetype ~= "wiki" then + return true + end + -- filter out by it's index number in list (don't show first buffer) + if buf_numbers[1] ~= buf_number then + return true + end + end, + -- offsets = {{filetype = "NvimTree", text = "File Explorer" | function , text_align = "left" | "center" | "right"}}, + show_buffer_icons = true, -- disable filetype icons for buffers + show_buffer_close_icons = false, + show_close_icon = false, + show_tab_indicators = true, + persist_buffer_sort = true, -- whether or not custom sorted buffers should persist + -- can also be a table containing 2 custom separators + -- [focused and unfocused]. eg: { '|', '|' } + separator_style = "thick", + enforce_regular_tabs = true, + always_show_bufferline = true, + sort_by = 'relative_directory' + end + } + } + EOF ''; }; }