diff options
| author | srdusr <trevorgray@srdusr.com> | 2024-03-01 17:22:21 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2024-03-01 17:22:21 +0200 |
| commit | 13b6952bf65988b1cbc0b1482aa1ace448a2b2d6 (patch) | |
| tree | 5a0b68b98370d4682a20ba06f003fc67916ceca4 | |
| parent | 71833aa16cc97c1327b6eb601fa9106fc7d41815 (diff) | |
| download | dotfiles-13b6952bf65988b1cbc0b1482aa1ace448a2b2d6.tar.gz dotfiles-13b6952bf65988b1cbc0b1482aa1ace448a2b2d6.zip | |
Completion for latex added
| -rw-r--r-- | lua/plugins/cmp.lua | 342 |
1 files changed, 182 insertions, 160 deletions
diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index edf57de..fe212fc 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -1,24 +1,22 @@ - -- Setup nvim-cmp. vim.opt.completeopt = "menu,menuone,noselect" --vim.g.completeopt = "menu,menuone,noselect,noinsert" local cmp_status_ok, cmp = pcall(require, "cmp") if not cmp_status_ok then - return + return end --local WIDE_HEIGHT = 40 local opts = { - -- whether to highlight the currently hovered symbol - -- disable if your cpu usage is higher than you want it - -- or you just hate the highlight - -- default: true - highlight_hovered_item = true, - show_guides = true, + -- whether to highlight the currently hovered symbol + -- disable if your cpu usage is higher than you want it + -- or you just hate the highlight + -- default: true + highlight_hovered_item = true, + show_guides = true, } require("symbols-outline").setup(opts) - --local snippets_paths = function() -- local plugins = { "friendly-snippets" } -- local paths = {} @@ -69,27 +67,27 @@ local kind_icons = { TypeParameter = "", } cmp.setup({ - snippet = { - --expand = function(args) - -- require("luasnip").lsp_expand(args.body) - --end, + snippet = { + --expand = function(args) + -- require("luasnip").lsp_expand(args.body) + --end, expand = function(args) local luasnip = require("luasnip") if not luasnip then - return + return end luasnip.lsp_expand(args.body) end, - }, - mapping = cmp.mapping.preset.insert({ --- ["<CR>"] = cmp.mapping.confirm({ --- behavior = cmp.ConfirmBehavior.Replace, --- select = true, --- }), + }, + mapping = cmp.mapping.preset.insert({ + -- ["<CR>"] = cmp.mapping.confirm({ + -- behavior = cmp.ConfirmBehavior.Replace, + -- select = true, + -- }), --["<C-k>"] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }), --["<C-j>"] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }), - ['<C-y>'] = cmp.mapping.confirm({ select = true }), - --["<C-e>"] = cmp.mapping.close(), + ["<C-y>"] = cmp.mapping.confirm({ select = true }), + --["<C-e>"] = cmp.mapping.close(), --['<C-e>'] = cmp.mapping({ -- i = cmp.mapping.abort(), -- c = cmp.mapping.close(), @@ -118,30 +116,30 @@ cmp.setup({ -- end, --}), --- ["<C-e>"] = cmp.mapping({ --- i = function() --- if cmp.visible() then --- require("notify")("visible") --- cmp.abort() --- else --- require("notify")("not visible") --- cmp.complete() --- end --- end, --- c = function() --- if cmp.visible() then --- require("notify")("visible") --- cmp.close() --- else --- require("notify")("not visible") --- cmp.complete() --- end --- end, --- }), + -- ["<C-e>"] = cmp.mapping({ + -- i = function() + -- if cmp.visible() then + -- require("notify")("visible") + -- cmp.abort() + -- else + -- require("notify")("not visible") + -- cmp.complete() + -- end + -- end, + -- c = function() + -- if cmp.visible() then + -- require("notify")("visible") + -- cmp.close() + -- else + -- require("notify")("not visible") + -- cmp.complete() + -- end + -- end, + -- }), --['<CR>'] = cmp.config.disable, - ["<C-u>"] = cmp.mapping.scroll_docs(-4), - ["<C-d>"] = cmp.mapping.scroll_docs(4), - ["<C-Space>"] = cmp.mapping.complete(), + ["<C-u>"] = cmp.mapping.scroll_docs(-4), + ["<C-d>"] = cmp.mapping.scroll_docs(4), + ["<C-Space>"] = cmp.mapping.complete(), --['<C-o>'] = function(fallback) -- if cmp.visible() then -- cmp.mapping.confirm({ select = true })(fallback) @@ -149,60 +147,60 @@ cmp.setup({ -- cmp.mapping.complete()(fallback) -- end --end - }), + }), sources = cmp.config.sources({ - --{ name = "nvim_lua" }, + --{ name = "nvim_lua" }, { name = "luasnip" }, - --{ name = 'luasnip', option = { use_show_condition = false } }, - { name = "gh_issues" }, - { name = "nvim_lsp", max_item_count = 6 }, + --{ name = 'luasnip', option = { use_show_condition = false } }, + { name = "gh_issues" }, + { name = "nvim_lsp", max_item_count = 6 }, { name = "nvim_lua" }, - --{ name = "luasnip" }, - --{ name = "luasnip", keyword_length = 4 }, - --{ name = "buffer", keyword_length = 3 }, - { name = "path" }, - { name = "buffer", max_item_count = 6 }, + --{ name = "luasnip" }, + --{ name = "luasnip", keyword_length = 4 }, + --{ name = "buffer", keyword_length = 3 }, + { name = "path" }, + { name = "buffer", max_item_count = 6 }, --{ name = "buffer", option = { get_bufnrs = function() -- return vim.api.nvim_list_bufs() --end --}}, - { name = "cmp_git"}, - { name = "spell"}, + { name = "cmp_git" }, + { name = "spell" }, { name = "zsh" }, { name = "treesitter" }, { name = "calc" }, { name = "nvim_lsp_signature_help" }, --{ name = "cmdline" }, --{ name = 'treesitter' }, - --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this - --{name = 'luasnip', keyword_length = 2}, - }), - formatting = { - --formatting = { - --local icons = kind_icons - --format = function(entry, vim_item) - ----vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) - ----vim_item.kind = lspkind.presets.default[vim_item.kind] - --vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind - ----vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) - --vim_item.menu = ({ - ----nvim_lsp = "LSP", - ----luasnip = "snip", - ----buffer = "buf", - ----path = "path", - ----cmdline = "cmd", - --buffer = "[buf]", - --nvim_lsp = "[LSP]", - --nvim_lua = "[api]", - --path = "[path]", - --luasnip = "[snip]", - --cmdline = "[cmd]", - --gh_issues = "[issues]", - --})[entry.source.name] - --return vim_item - --end, - format = lspkind.cmp_format { + --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this + --{name = 'luasnip', keyword_length = 2}, + }), + formatting = { + --formatting = { + --local icons = kind_icons + --format = function(entry, vim_item) + ----vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + ----vim_item.kind = lspkind.presets.default[vim_item.kind] + --vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + ----vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) + --vim_item.menu = ({ + ----nvim_lsp = "LSP", + ----luasnip = "snip", + ----buffer = "buf", + ----path = "path", + ----cmdline = "cmd", + --buffer = "[buf]", + --nvim_lsp = "[LSP]", + --nvim_lua = "[api]", + --path = "[path]", + --luasnip = "[snip]", + --cmdline = "[cmd]", + --gh_issues = "[issues]", + --})[entry.source.name] + --return vim_item + --end, + format = lspkind.cmp_format({ with_text = true, menu = { nvim_lsp = "[LSP]", @@ -216,19 +214,18 @@ cmp.setup({ treesitter = "[treesitter]", calc = "[calc]", nvim_lsp_signature_help = "[signature]", - cmdline = "[cmd]" - + cmdline = "[cmd]", }, - }, - --}, + }), + --}, -- -- - --fields = { "abbr", "kind", "menu" }, - -- format = lspkind.cmp_format({ - -- mode = 'symbol_text', -- 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) - -- }) + --fields = { "abbr", "kind", "menu" }, + -- format = lspkind.cmp_format({ + -- mode = 'symbol_text', -- 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) + -- }) --format = require('lspkind').cmp_format { -- with_text = true, -- menu = { @@ -241,92 +238,117 @@ cmp.setup({ -- }, --}, }, - --format = function(entry, vim_item) - -- -- Kind icons - -- --vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) - -- vim_item.kind = lspkind.presets.default[vim_item.kind] - -- -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind - -- vim_item.menu = ({ - -- nvim_lsp = "LSP", - -- luasnip = "Snip", - -- buffer = "Buf", - -- path = "Path", - -- cmdline = "Cmd", - -- })[entry.source.name] - -- return vim_item - --end, + --format = function(entry, vim_item) + -- -- Kind icons + -- --vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + -- vim_item.kind = lspkind.presets.default[vim_item.kind] + -- -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + -- vim_item.menu = ({ + -- nvim_lsp = "LSP", + -- luasnip = "Snip", + -- buffer = "Buf", + -- path = "Path", + -- cmdline = "Cmd", + -- })[entry.source.name] + -- return vim_item + --end, confirm_opts = { - behavior = cmp.ConfirmBehavior.Replace, - select = false, - }, - + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, event = {}, - experimental = { - ghost_text = true, -- this feature conflicts with copilot.vim's preview. - hl_group = 'Nontext', - --native_menu = false, - }, + experimental = { + ghost_text = true, -- this feature conflicts with copilot.vim's preview. + hl_group = "Nontext", + --native_menu = false, + }, - view = { - entries = { name = 'custom', selection_order = 'top_down' }, - }, + view = { + entries = { name = "custom", selection_order = "top_down" }, + }, - window = { - --completion = cmp.config.window.bordered(), - completion = { - border = { '', '', '', ' ', '', '', '', ' ' }, - --border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - --border = { '', '', '', '', '', '', '', '' }, - --border = "CmpBorder", - winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None', - --winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", - }, - --documentation = cmp.config.window.bordered(), - documentation = { - --max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)), - --max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))), - border = { '', '', '', ' ', '', '', '', ' ' }, - --border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - winhighlight = 'FloatBorder:NormalFloat', - }, + window = { + --completion = cmp.config.window.bordered(), + completion = { + border = { "", "", "", " ", "", "", "", " " }, + --border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + --border = { '', '', '', '', '', '', '', '' }, + --border = "CmpBorder", + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None", + --winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", + }, + --documentation = cmp.config.window.bordered(), + documentation = { + --max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)), + --max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))), + border = { "", "", "", " ", "", "", "", " " }, + --border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + winhighlight = "FloatBorder:NormalFloat", }, + }, }) - -cmp.setup.cmdline({ '/', '?' }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = "buffer" }, +cmp.setup.cmdline({ "/", "?" }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, }, }) cmp.setup.cmdline(":", { mapping = { - ["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }), - ["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }), - ["<C-y>"] = cmp.mapping(cmp.mapping.confirm({ select = true }), { 'i', 'c' }), - ["<C-e>"] = cmp.mapping(cmp.mapping.close(), { 'i', 'c' }), - ["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), - ["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), - ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + ["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }), + ["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), + ["<C-y>"] = cmp.mapping(cmp.mapping.confirm({ select = true }), { "i", "c" }), + ["<C-e>"] = cmp.mapping(cmp.mapping.close(), { "i", "c" }), + ["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), + ["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), + ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), --["<C-k>"] = cmp.mapping.select_prev_item(), --["<C-j>"] = cmp.mapping.select_next_item(), --['<C-y>'] = cmp.mapping.confirm({ select = true }), - --["<C-e>"] = cmp.mapping.close(), + --["<C-e>"] = cmp.mapping.close(), ----['<CR>'] = cmp.config.disable, - --["<C-u>"] = cmp.mapping.scroll_docs(-4), - --["<C-d>"] = cmp.mapping.scroll_docs(4), - --["<C-Space>"] = cmp.mapping.complete(), + --["<C-u>"] = cmp.mapping.scroll_docs(-4), + --["<C-d>"] = cmp.mapping.scroll_docs(4), + --["<C-Space>"] = cmp.mapping.complete(), }, - sources = cmp.config.sources({ - { name = "path" }, - }, { - --{ name = "cmdline" }, + sources = cmp.config.sources({ + { name = "path" }, + }, { + --{ name = "cmdline" }, { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 }, - }) + }), }) - +return { + "micangl/cmp-vimtex", + config = function() + require("cmp_vimtex").setup({ + additional_information = { + info_in_menu = true, + info_in_window = true, + info_max_length = 60, + match_against_info = true, + symbols_in_menu = true, + }, + bibtex_parser = { + enabled = true, + }, + search = { + browser = "xdg-open", + default = "google_scholar", + search_engines = { + google_scholar = { + name = "Google Scholar", + get_url = require("cmp_vimtex").url_default_format("https://scholar.google.com/scholar?hl=en&q=%s"), + }, + -- Other search engines. + }, + }, + }) + end, +} |
