From 352a161faf40107551dc84edb335fe96915fd04e Mon Sep 17 00:00:00 2001 From: xieby1 Date: Fri, 31 May 2024 22:49:20 +0800 Subject: [PATCH] usr: cli: split vim: nvim-cmp --- usr/cli/vim/default.nix | 112 +-------------------------------------- usr/cli/vim/nvim-cmp.nix | 110 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 110 deletions(-) create mode 100644 usr/cli/vim/nvim-cmp.nix diff --git a/usr/cli/vim/default.nix b/usr/cli/vim/default.nix index 492fcdb1..8822eaeb 100644 --- a/usr/cli/vim/default.nix +++ b/usr/cli/vim/default.nix @@ -391,116 +391,8 @@ in ./nvim-metals ./conform-nvim.nix ./nvim-lspconfig.nix - ] ++ [(let - my-nvim-cmp = { - plugin = pkgs.vimPlugins.nvim-cmp; - type = "lua"; - config = '' - local cmp = require'cmp' - - cmp.setup({ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), -- Up - [''] = cmp.mapping.scroll_docs(4), -- Down - -- C-b (back) C-f (forward) for snippet placeholder navigation. - [''] = cmp.mapping.complete(), - - -- https://github.com/hrsh7th/nvim-cmp/issues/1753 - -- The "Safely select entries with " example from wiki does not work correctly in command mode - [""] = cmp.mapping({ - i = function(fallback) - if cmp.visible() and cmp.get_active_entry() then - cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) - else - fallback() - end - end, - s = cmp.mapping.confirm({ select = true }), - c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), - }), - - [''] = 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' }), - }), - sources = cmp.config.sources({{ - name = 'nvim_lsp', - }}, {{ - name = 'luasnip', - }}, {{ - name = 'buffer', - option = { - -- completion using words from 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 - }, - }}, {{ - name = 'path', - '' + pkgs.lib.optionalString (builtins.currentSystem=="x86_64-linux") '' - }}, {{ - name = 'cmp_tabnine', - '' + '' - }}) - }) - ''; - }; - my-cmp-tabnine = { - plugin = pkgs.vimPlugins.cmp-tabnine; - type = "lua"; - config = '' - local tabnine = require('cmp_tabnine.config') - - tabnine:setup({ - max_lines = 1000, - max_num_results = 20, - sort = true, - run_on_every_keystroke = true, - snippet_placeholder = '..', - ignored_file_types = { - -- default is not to ignore - -- uncomment to ignore in lua: - -- lua = true - }, - show_prediction_strength = false - }) - ''; - }; - in { - programs.neovim = { - plugins = with pkgs.vimPlugins; [ - my-nvim-cmp - cmp-nvim-lsp - cmp-buffer - cmp-path - luasnip - cmp_luasnip - ] ++ pkgs.lib.optional (builtins.currentSystem == "x86_64-linux") my-cmp-tabnine; - extraPackages = with pkgs; [ - ]; - }; - })]; + ./nvim-cmp.nix + ]; # neovim programs.bash.shellAliases.view = "nvim -R"; diff --git a/usr/cli/vim/nvim-cmp.nix b/usr/cli/vim/nvim-cmp.nix new file mode 100644 index 00000000..0bc7f7fe --- /dev/null +++ b/usr/cli/vim/nvim-cmp.nix @@ -0,0 +1,110 @@ +#MC # nvim-cmp: completion +{ config, pkgs, stdenv, lib, ... }: +let + my-nvim-cmp = { + plugin = pkgs.vimPlugins.nvim-cmp; + type = "lua"; + config = '' + local cmp = require'cmp' + + cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), -- Up + [''] = cmp.mapping.scroll_docs(4), -- Down + -- C-b (back) C-f (forward) for snippet placeholder navigation. + [''] = cmp.mapping.complete(), + + -- https://github.com/hrsh7th/nvim-cmp/issues/1753 + -- The "Safely select entries with " example from wiki does not work correctly in command mode + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) + else + fallback() + end + end, + s = cmp.mapping.confirm({ select = true }), + c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + }), + + [''] = 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' }), + }), + sources = cmp.config.sources({{ + name = 'nvim_lsp', + }}, {{ + name = 'luasnip', + }}, {{ + name = 'buffer', + option = { + -- completion using words from 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 + }, + }}, {{ + name = 'path', + '' + pkgs.lib.optionalString (builtins.currentSystem=="x86_64-linux") '' + }}, {{ + name = 'cmp_tabnine', + '' + '' + }}) + }) + ''; + }; + my-cmp-tabnine = { + plugin = pkgs.vimPlugins.cmp-tabnine; + type = "lua"; + config = '' + local tabnine = require('cmp_tabnine.config') + + tabnine:setup({ + max_lines = 1000, + max_num_results = 20, + sort = true, + run_on_every_keystroke = true, + snippet_placeholder = '..', + ignored_file_types = { + -- default is not to ignore + -- uncomment to ignore in lua: + -- lua = true + }, + show_prediction_strength = false + }) + ''; + }; +in { + programs.neovim = { + plugins = with pkgs.vimPlugins; [ + my-nvim-cmp + cmp-nvim-lsp + cmp-buffer + cmp-path + luasnip + cmp_luasnip + ] ++ pkgs.lib.optional (builtins.currentSystem == "x86_64-linux") my-cmp-tabnine; + }; +}