diff --git a/jrpotter/neovim/default.nix b/jrpotter/neovim/default.nix index b525f57..ad8634f 100644 --- a/jrpotter/neovim/default.nix +++ b/jrpotter/neovim/default.nix @@ -9,6 +9,13 @@ let }; }; + nvim-cmp = { + plugin = pkgs.vimPlugins.nvim-cmp; + config = '' + require('init.cmp').setup() + ''; + }; + nvim-dap = { plugin = pluginGit "e154fdb6d70b3765d71f296e718b29d8b7026a63" @@ -30,19 +37,7 @@ let ] )); config = '' - require('nvim-treesitter.configs').setup { - auto_install = false, - highlight = { enable = true }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - node_decremental = '', - scope_incremental = false, - }, - }, - } + require('init.treesitter').setup() ''; }; in @@ -83,9 +78,12 @@ in inherit (p) plugin; config = "lua << EOF\n${p.config}\nEOF"; } else p) [ + nvim-cmp nvim-dap nvim-lspconfig nvim-treesitter + pkgs.vimPlugins.cmp-buffer + pkgs.vimPlugins.cmp-nvim-lsp ]; viAlias = true; vimAlias = true; diff --git a/jrpotter/neovim/lua/init/cmp.lua b/jrpotter/neovim/lua/init/cmp.lua new file mode 100644 index 0000000..8d5c90d --- /dev/null +++ b/jrpotter/neovim/lua/init/cmp.lua @@ -0,0 +1,55 @@ +local M = {} + +local cmp = require('cmp') +local cmp_buffer = require('cmp_buffer') + +function M.setup() + cmp.setup { + sources = { + { + name = 'nvim_lsp', + }, + { + name = 'buffer', + option = { + -- Complete only on visible buffers. + get_bufnrs = function() + local bufs = {} + for _, win in ipairs(vim.api.nvim_list_wins()) do + bufs[vim.api.nvim_win_get_buf(win)] = true + end + return vim.tbl_keys(bufs) + end + }, + }, + }, + sorting = { + comparators = { + function (...) + -- This also sorts completion results coming from other sources (e.g. + -- LSPs). + return cmp_buffer:compare_locality(...) + end, + }, + }, + mapping = { + [''] = cmp.mapping(function(fallback) + if cmp.visible() then cmp.select_next_item() else fallback() end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then cmp.select_prev_item() else fallback() end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then cmp.abort() else fallback() end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then cmp.confirm() else fallback() end + end, { 'i', 's' }), + }, + } +end + +return M diff --git a/jrpotter/neovim/lua/init/treesitter.lua b/jrpotter/neovim/lua/init/treesitter.lua new file mode 100644 index 0000000..7fb3b82 --- /dev/null +++ b/jrpotter/neovim/lua/init/treesitter.lua @@ -0,0 +1,12 @@ +local M = {} + +local configs = require('nvim-treesitter.configs') + +function M.setup() + configs.setup { + auto_install = false, + highlight = { enable = true }, + } +end + +return M