From cc77bf697a6e128f24f5029284c08e6edf3baca0 Mon Sep 17 00:00:00 2001 From: Anish L Date: Sat, 26 Feb 2022 13:31:21 +1000 Subject: [PATCH] working nvim config with nice autocomplete --- profiles/nvim/nvim.nix | 178 +++++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 76 deletions(-) diff --git a/profiles/nvim/nvim.nix b/profiles/nvim/nvim.nix index fdfcf5a7..84a23f91 100644 --- a/profiles/nvim/nvim.nix +++ b/profiles/nvim/nvim.nix @@ -21,18 +21,8 @@ let sha256 = "000000000000000000000000PJ023iJyMz6vak3qh4="; }; }; - taskwiki-t = pkgs.vimUtils.buildVimPluginFrom2Nix { - pname = "taskwiki"; - version = "2021-09-22"; - src = pkgs.fetchFromGitHub { - owner = "tools-life"; - repo = "taskwiki"; - rev = "c4392c36c01cfffcb06f460d722990b98bc53bdb"; - sha256 = "QrxFqu/Y6FykXGqIlK52+nDwmnBhubURl6v2Zc/KwPw="; - }; - meta.homepage = "https://github.com/tools-life/taskwiki/"; - }; }; + my-python-packages = python-packages: with python-packages; [ tasklib pynvim @@ -65,6 +55,7 @@ in configure = { packages.myPlugins = with pkgs.vimPlugins; { start = [ + # general vim-nix fzf-vim vim-elixir @@ -77,6 +68,9 @@ in rainbow_parentheses-vim vim-surround vim-devicons + nvim-web-devicons + direnv-vim + # kitaab stuff vimwiki taskwiki @@ -84,6 +78,7 @@ in telescope-nvim plenary-nvim bufferline-nvim + # lsp stuff ale nvim-lspconfig @@ -94,10 +89,15 @@ in cmp-buffer cmp-tabnine lspkind-nvim + cmp-path + cmp-spell + nvim-autopairs + # git stuff vim-fugitive gitsigns-nvim fzf-checkout-vim + # Clojure stuff conjure vim-sexp @@ -133,6 +133,22 @@ in " set spell set spelllang=en_gb + set ignorecase + set smartcase + set incsearch + " if hidden is not set, TextEdit might fail. + set hidden + " Some servers have issues with backup files, see #649 + set nobackup + set nowritebackup + " Better display for messages + set cmdheight=2 + " You will have bad experience for diagnostic messages when it's default 4000. + set updatetime=300 + " don't give |ins-completion-menu| messages. + set shortmess+=c + " always show signcolumns + set signcolumn=yes " window nmap wh :topleft vnew @@ -168,6 +184,7 @@ in nnoremap fg Telescope live_grep nnoremap fb Telescope buffers nnoremap fh Telescope help_tags + nnoremap ft Telescope tags " exit normal mode in terminal :tnoremap @@ -176,7 +193,7 @@ in " let g:sexp_filetypes = [ "fennel" ] let g:rainbow_active = 0 - autocmd BufReadPost,BufNewFile c,py,nix RainbowParenthesesToggleAll + autocmd BufReadPost,BufNewFile c,clj,cljs RainbowParenthesesToggleAll " general commands map t :NERDTreeToggle @@ -234,29 +251,9 @@ in " fzf let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } } - " ALE + clj-kondo + " ALE let g:ale_linters = {'clojure': ['clj-kondo'], 'python': ['black', 'pylint']} - " if hidden is not set, TextEdit might fail. - set hidden - - " Some servers have issues with backup files, see #649 - set nobackup - set nowritebackup - - " Better display for messages - set cmdheight=2 - - " You will have bad experience for diagnostic messages when it's default 4000. - set updatetime=300 - - " don't give |ins-completion-menu| messages. - set shortmess+=c - - " always show signcolumns - set signcolumn=yes - - " lsp commands nnoremap vd :lua vim.lsp.buf.definition() nnoremap vi :lua vim.lsp.buf.implementation() @@ -277,51 +274,80 @@ in " lua config lua <'] = 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 = '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' } - }) -}) +local cmp = require('cmp') +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end +local check_back_space = function() + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil +end +cmp.setup { + formatting = { + format = function(entry, vim_item) + -- fancy icons and a name of kind + vim_item.kind = require("lspkind").presets.default[vim_item.kind] .. + " " .. vim_item.kind + -- set a name for each source + vim_item.menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + cmp_tabnine = "[TabNine]", + look = "[Look]", + path = "[Path]", + spell = "[Spell]", + calc = "[Calc]", + })[entry.source.name] + return vim_item + end + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, {"i", "s"}), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { "i", "s" }), + }, + sources = { + {name = 'buffer'}, {name = 'nvim_lsp'}, + {name = "look"}, {name = "path"}, + {name = 'cmp_tabnine'}, {name = "calc"}, {name = "spell"}, + {name = 'cmp-conjure'} + }, + completion = {completeopt = 'menu,menuone,noinsert'} +} +-- TabNine cmp +local tabnine = require('cmp_tabnine.config') +tabnine:setup({max_lines = 1000, max_num_results = 20, sort = true}) -- Setup lspconfig. --- local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) --- require'lspconfig'nvim_lsp.setup {} --- require'lspconfig'clojure_lsp.setup {} --- require'lspconfig'rnix.setup {} --- require'lspconfig'pylsp.setup {} --- require'lspconfig'terraform_lsp.setup {} +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +require'lspconfig'nvim_lsp.setup {} +require'lspconfig'clojure_lsp.setup {} +require'lspconfig'rnix.setup {} +require'lspconfig'pylsp.setup {} +require'lspconfig'terraform_lsp.setup {} -- Bufferline require('bufferline').setup {}