From 3cda0b269681ca98ff2fe3daaa28e128b998859f Mon Sep 17 00:00:00 2001 From: newbie Date: Thu, 23 Nov 2023 18:39:37 +0800 Subject: [PATCH] updaye --- lua/plugs.lua | 8 +- lua/plugs/coc.lua | 173 ----------------------------------- lua/plugs/copilot.lua | 9 ++ lua/plugs/lualine.lua | 74 --------------- lua/plugs/nvim-lspconfig.lua | 118 ++++++++++++++++++------ lua/plugs/theme.lua | 75 ++++++++++++++- lua/plugs/treesitter.lua | 58 ------------ 7 files changed, 176 insertions(+), 339 deletions(-) delete mode 100644 lua/plugs/coc.lua create mode 100644 lua/plugs/copilot.lua delete mode 100644 lua/plugs/lualine.lua delete mode 100644 lua/plugs/treesitter.lua diff --git a/lua/plugs.lua b/lua/plugs.lua index ef14704..fba8441 100644 --- a/lua/plugs.lua +++ b/lua/plugs.lua @@ -1,18 +1,14 @@ return { - 'github/copilot.vim', -- github copilot 'vijaymarupudi/nvim-fzf', -- fzf 'lilydjwg/colorizer', -- 颜色识别 - - -- require('plugs.coc'), -- coc - require('plugs.nvim-lspconfig'), -- - require('plugs.lualine'), -- lualine + require('plugs.nvim-lspconfig'), require('plugs.nvimtree'), -- nvimtree - require('plugs.treesitter'), -- treesitter require('plugs.theme'), -- theme + require("plugs.copilot"), require("plugs.edit-plugs"), require("plugs.hop"), require("plugs.toggleterm") diff --git a/lua/plugs/coc.lua b/lua/plugs/coc.lua deleted file mode 100644 index a0bb6f4..0000000 --- a/lua/plugs/coc.lua +++ /dev/null @@ -1,173 +0,0 @@ -return { - { - 'neoclide/coc.nvim', - config = function() - - G.opt.backup = false - G.opt.writebackup = false - G.opt.updatetime = 300 - G.opt.signcolumn = "yes" - G.g.coc_global_extensions = { - 'coc-json', - 'coc-pyright', - 'coc-java', - 'coc-sh', - 'coc-sumneko-lua', - 'coc-clangd', - - 'coc-word', - 'coc-lists', - 'coc-pairs', - 'coc-marketplace', - - } - - local opts = { - silent = true, - noremap = true, - expr = true, - replace_keycodes = false - } - - G.map({ - --- { "i", "", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh()', opts }, --- { "i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], opts }, - - { "i", "", [[coc#pum#visible() ? coc#pum#confirm() : "\u\\=coc#on_enter()\"]], opts }, - - { "n", "gd", "(coc-definition)", {silent = true} }, - { "n", "gy", "(coc-type-definition)", {silent = true} }, - { "n", "gi", "(coc-implementation)", {silent = true} }, - { "n", "gr", "(coc-references)", {silent = true} }, - { "n", "rn", "(coc-rename)", {silent = true} }, - - { "v", "", "(coc-format-selected)", {silent = true} }, - -- { "n", "", "(coc-format-selected)", {silent = true} }, - - }) - -- local keyset = vim.keymap.set - - - function _G.check_back_space() - local col = G.fn.col('.') - 1 - return col == 0 or G.fn.getline('.'):sub(col, col):match('%s') ~= nil - end - - -- keyset("n", "[g", "(coc-diagnostic-prev)", {silent = true}) - -- keyset("n", "]g", "(coc-diagnostic-next)", {silent = true}) - - G.api.nvim_create_augroup("CocGroup", {}) - G.au("CursorHold", { - group = "CocGroup", - command = "silent call CocActionAsync('highlight')", - desc = "Highlight symbol under cursor on CursorHold" - }) - - - G.au("FileType", { - group = "CocGroup", - pattern = "typescript,json", - command = "setl formatexpr=CocAction('formatSelected')", - desc = "Setup formatexpr specified filetype(s)." - }) - - -- Update signature help on jump placeholder - G.au("User", { - group = "CocGroup", - pattern = "CocJumpPlaceholder", - command = "call CocActionAsync('showSignatureHelp')", - desc = "Update signature help on jump placeholder" - }) - - -- Apply codeAction to the selected region - -- Example: `aap` for current paragraph - --local opts = {silent = true, nowait = true} - --keyset("x", "a", "(coc-codeaction-selected)", opts) - --keyset("n", "a", "(coc-codeaction-selected)", opts) - - ---- Remap keys for apply code actions at the cursor position. - --keyset("n", "ac", "(coc-codeaction-cursor)", opts) - ---- Remap keys for apply source code actions for current file. - --keyset("n", "as", "(coc-codeaction-source)", opts) - ---- Apply the most preferred quickfix action on the current line. - --keyset("n", "qf", "(coc-fix-current)", opts) - - ---- Remap keys for apply refactor code actions. - --keyset("n", "re", "(coc-codeaction-refactor)", { silent = true }) - --keyset("x", "r", "(coc-codeaction-refactor-selected)", { silent = true }) - --keyset("n", "r", "(coc-codeaction-refactor-selected)", { silent = true }) - - ---- Run the Code Lens actions on the current line - --keyset("n", "cl", "(coc-codelens-action)", opts) - - - ---- Map function and class text objects - ---- NOTE: Requires 'textDocument.documentSymbol' support from the language server - --keyset("x", "if", "(coc-funcobj-i)", opts) - --keyset("o", "if", "(coc-funcobj-i)", opts) - --keyset("x", "af", "(coc-funcobj-a)", opts) - --keyset("o", "af", "(coc-funcobj-a)", opts) - --keyset("x", "ic", "(coc-classobj-i)", opts) - --keyset("o", "ic", "(coc-classobj-i)", opts) - --keyset("x", "ac", "(coc-classobj-a)", opts) - --keyset("o", "ac", "(coc-classobj-a)", opts) - - - ---- Remap and to scroll float windows/popups - -----@diagnostic disable-next-line: redefined-local - --local opts = {silent = true, nowait = true, expr = true} - --keyset("n", "", 'coc#float#has_scroll() ? coc#float#scroll(1) : ""', opts) - --keyset("n", "", 'coc#float#has_scroll() ? coc#float#scroll(0) : ""', opts) - --keyset("i", "", - -- 'coc#float#has_scroll() ? "=coc#float#scroll(1)" : ""', opts) - --keyset("i", "", - -- 'coc#float#has_scroll() ? "=coc#float#scroll(0)" : ""', opts) - --keyset("v", "", 'coc#float#has_scroll() ? coc#float#scroll(1) : ""', opts) - --keyset("v", "", 'coc#float#has_scroll() ? coc#float#scroll(0) : ""', opts) - - - ---- Use CTRL-S for selections ranges - ---- Requires 'textDocument/selectionRange' support of language server - --keyset("n", "", "(coc-range-select)", {silent = true}) - --keyset("x", "", "(coc-range-select)", {silent = true}) - - - ---- Add `:Format` command to format current buffer - --vim.api.nvim_create_user_command("Format", "call CocAction('format')", {}) - - ---- " Add `:Fold` command to fold current buffer - --vim.api.nvim_create_user_command("Fold", "call CocAction('fold', )", {nargs = '?'}) - - ---- Add `:OR` command for organize imports of the current buffer - --vim.api.nvim_create_user_command("OR", "call CocActionAsync('runCommand', 'editor.action.organizeImport')", {}) - - ---- Add (Neo)Vim's native statusline support - ---- NOTE: Please see `:h coc-status` for integrations with external plugins that - ---- provide custom statusline: lightline.vim, vim-airline - --vim.opt.statusline:prepend("%{coc#status()}%{get(b:,'coc_current_function','')}") - - - ---- Mappings for CoCList - ---- code actions and coc stuff - -----@diagnostic disable-next-line: redefined-local - --local opts = {silent = true, nowait = true} - ---- Show all diagnostics - --keyset("n", "a", ":CocList diagnostics", opts) - ---- Manage extensions - --keyset("n", "e", ":CocList extensions", opts) - ---- Show commands - --keyset("n", "c", ":CocList commands", opts) - ---- Find symbol of current document - --keyset("n", "o", ":CocList outline", opts) - ---- Search workspace symbols - --keyset("n", "s", ":CocList -I symbols", opts) - ---- Do default action for next item - --keyset("n", "j", ":CocNext", opts) - ---- Do default action for previous item - --keyset("n", "k", ":CocPrev", opts) - ---- Resume latest coc list - --keyset("n", "p", ":CocListResume", opts) - end, - }, -} diff --git a/lua/plugs/copilot.lua b/lua/plugs/copilot.lua new file mode 100644 index 0000000..84504ff --- /dev/null +++ b/lua/plugs/copilot.lua @@ -0,0 +1,9 @@ +return { + 'github/copilot.vim', -- github copilot + config = function () + G.g.copilot_no_tab_map = true + G.map({ + {"i", '', "copilot#Accept()", {silent = true}}, + }) + end +} diff --git a/lua/plugs/lualine.lua b/lua/plugs/lualine.lua deleted file mode 100644 index a94a0b3..0000000 --- a/lua/plugs/lualine.lua +++ /dev/null @@ -1,74 +0,0 @@ -return { - 'nvim-lualine/lualine.nvim', - dependencies = { - 'kdheepak/tabline.nvim', - }, - config = function() - require('lualine').setup { - options = { - icons_enabled = true, - theme = 'auto', - component_separators = { left = '', right = ''}, - section_separators = { left = '', right = ''}, - disabled_filetypes = { - statusline = {}, - winbar = {}, - }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = false, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - } - }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', 'diagnostics'}, - lualine_c = {{ - 'filename', - file_status = false, - path = 1 - }}, - lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_y = {'progress'}, - lualine_z = {} - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {'filename'}, - lualine_x = {'location'}, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {} - } - require('tabline').setup { - -- Defaults configuration options - enable = true, - options = { - -- If lualine is installed tabline will use separators configured in lualine by default. - -- These options can be used to override those settings. - section_separators = {' ', ' '}, - component_separators = {'', ''}, - max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 - show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named - show_devicons = true, -- this shows devicons in buffer section - show_bufnr = false, -- this appends [bufnr] to buffer section, - show_filename_only = true, -- shows base filename only instead of relative path in filename - modified_icon = "+ ", -- change the default modified icon - modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified - show_tabs_only = false, -- this shows only tabs instead of tabs + buffers - }, - G.cmd[[ - set guioptions-=e " Use showtabline in gui vim - set sessionoptions+=tabpages,globals " store tabpages and globals in session - ]] - } - end, -} diff --git a/lua/plugs/nvim-lspconfig.lua b/lua/plugs/nvim-lspconfig.lua index 01f6e84..79781a7 100644 --- a/lua/plugs/nvim-lspconfig.lua +++ b/lua/plugs/nvim-lspconfig.lua @@ -1,21 +1,26 @@ + return { { + -- lsp的config "neovim/nvim-lspconfig", config = function () require'lspconfig'.lua_ls.setup(require('lsp.lua')) end }, { + -- lsp 下载器 "williamboman/mason.nvim", config = function() require("mason").setup({}) end }, { + -- lsp补全 'hrsh7th/cmp-nvim-lsp', -- { name = 'nvim_lua' } 'hrsh7th/cmp-buffer', -- { name = 'buffer' }, 'hrsh7th/cmp-path', -- { name = 'path' } 'hrsh7th/cmp-cmdline', -- { name = 'cmdline' } + 'hrsh7th/vim-vsnip', 'hrsh7th/cmp-vsnip', { 'onsails/lspkind-nvim', @@ -61,37 +66,45 @@ return { local line, col = unpack(G.api.nvim_win_get_cursor(0)) return col ~= 0 and G.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil end + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end local cmp = require('cmp') local lspkind = require('lspkind') cmp.setup { + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + end, + }, sources = cmp.config.sources({ + { name = 'vnsip'}, { name = 'nvim_lsp' }, { name = 'buffer' }, { name = 'path' }, { name = 'cmdline' }, - {name = 'vnsip'}, }), mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [''] = function(fallback) - if not cmp.select_next_item() then - if vim.bo.buftype ~= 'prompt' and has_words_before() then - cmp.complete() - else - fallback() - end + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() end - end, + end, { "i", "s" }), - [''] = function(fallback) - if not cmp.select_prev_item() then - if vim.bo.buftype ~= 'prompt' and has_words_before() then - cmp.complete() - else - fallback() - end + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") end - end, + end, { "i", "s" }), }), window = { @@ -103,22 +116,75 @@ return { }, fomatting = { format = lspkind.cmp_format({ - mode = 'symbol', -- show only symbol annotations - maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) - ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) + mode = 'symbol', + maxwidth = 50, + ellipsis_char = '...', before = function (_, vim_item) return vim_item end }) }, - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end, - }, } end, - } + }, + { + -- 语法高亮 + 'nvim-treesitter/nvim-treesitter', + config = function() + require'nvim-treesitter.configs'.setup{ + -- A list of parser names, or "all" (the four listed parsers should always be installed) + ensure_installed = {}, + + indent = { enable = true }, + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, + + -- List of parsers to ignore installing (for "all") + -- ignore_install = { "javascript" }, + + ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) + -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! + + highlight = { + -- `false` will disable the whole extension + enable = true, + + -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to + -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is + -- the name of the parser) + -- list of language that will be disabled + -- disable = { "c", "rust" }, + -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + + -- 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, + }, + parsers = { + html = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-vue", + files = {"src/parser.c"}, + branch = "main" + } + } + } + } + end + }, } } diff --git a/lua/plugs/theme.lua b/lua/plugs/theme.lua index 939d392..c7211d3 100644 --- a/lua/plugs/theme.lua +++ b/lua/plugs/theme.lua @@ -1,12 +1,83 @@ return { - 'shaunsingh/nord.nvim', -- 主题插件 { 'folke/tokyonight.nvim', config = function () G.cmd("colorscheme tokyonight") -- 主题 - -- G.api.colorscheme = "tokyonight" G.opt.background = 'dark' -- 背景 end + }, + { + -- line插件 + 'kdheepak/tabline.nvim', + 'nvim-lualine/lualine.nvim', + config = function() + require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {{ + 'filename', + file_status = false, + path = 1 + }}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = {'progress'}, + lualine_z = {} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} + } + require('tabline').setup { + -- Defaults configuration options + enable = true, + options = { + -- If lualine is installed tabline will use separators configured in lualine by default. + -- These options can be used to override those settings. + section_separators = {' ', ' '}, + component_separators = {'', ''}, + max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3 + show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named + show_devicons = true, -- this shows devicons in buffer section + show_bufnr = false, -- this appends [bufnr] to buffer section, + show_filename_only = true, -- shows base filename only instead of relative path in filename + modified_icon = "+ ", -- change the default modified icon + modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified + show_tabs_only = false, -- this shows only tabs instead of tabs + buffers + }, + G.cmd[[ + set guioptions-=e " Use showtabline in gui vim + set sessionoptions+=tabpages,globals " store tabpages and globals in session + ]] + } + end, } } diff --git a/lua/plugs/treesitter.lua b/lua/plugs/treesitter.lua deleted file mode 100644 index d8a1fe2..0000000 --- a/lua/plugs/treesitter.lua +++ /dev/null @@ -1,58 +0,0 @@ -return { - -- 语法高亮 - 'nvim-treesitter/nvim-treesitter', - config = function() - require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" (the four listed parsers should always be installed) - ensure_installed = {}, - - indent = { enable = true }, - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - - -- Automatically install missing parsers when entering buffer - -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally - auto_install = true, - - -- List of parsers to ignore installing (for "all") - -- ignore_install = { "javascript" }, - - ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) - -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! - - highlight = { - -- `false` will disable the whole extension - enable = true, - - -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to - -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is - -- the name of the parser) - -- list of language that will be disabled - -- disable = { "c", "rust" }, - -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files - disable = function(lang, buf) - local max_filesize = 100 * 1024 -- 100 KB - local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf)) - if ok and stats and stats.size > max_filesize then - return true - end - end, - - -- 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, - }, - parsers = { - html = { - install_info = { - url = "https://github.com/ikatyang/tree-sitter-vue", - files = {"src/parser.c"}, - branch = "main" - } - } - } - } - end -}