summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/plugins
diff options
context:
space:
mode:
authorYigit Sever2023-09-03 20:26:08 +0300
committerYigit Sever2023-09-03 20:26:08 +0300
commitf69e8f3c3259460fe6842a951c8c4d2728a67f57 (patch)
treed48092ed21016b93e0d9c44e39cd0cfae10c72b8 /.config/nvim/lua/plugins
parent0fca0070797db185316e91668741bc3eab401cd4 (diff)
downloaddotfiles-f69e8f3c3259460fe6842a951c8c4d2728a67f57.tar.gz
dotfiles-f69e8f3c3259460fe6842a951c8c4d2728a67f57.tar.bz2
dotfiles-f69e8f3c3259460fe6842a951c8c4d2728a67f57.zip
nvim: cmp cleanup, actually use luasnip
Diffstat (limited to '.config/nvim/lua/plugins')
-rw-r--r--.config/nvim/lua/plugins/cmp.lua82
1 files changed, 39 insertions, 43 deletions
diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua
index 7f3163f..1bc209f 100644
--- a/.config/nvim/lua/plugins/cmp.lua
+++ b/.config/nvim/lua/plugins/cmp.lua
@@ -1,16 +1,16 @@
1return { 1return {
2 { 2 {
3 "hrsh7th/nvim-cmp", 3 "hrsh7th/nvim-cmp",
4 event = "InsertEnter",
5 dependencies = { 4 dependencies = {
6 "hrsh7th/cmp-nvim-lsp", 5 "hrsh7th/cmp-nvim-lsp",
7 "hrsh7th/cmp-nvim-lua", 6 "hrsh7th/cmp-nvim-lua",
8 "hrsh7th/cmp-buffer", 7 "hrsh7th/cmp-buffer",
9 "hrsh7th/cmp-path", 8 "hrsh7th/cmp-path",
10 "hrsh7th/cmp-omni", 9 "hrsh7th/cmp-omni",
10 "hrsh7th/cmp-nvim-lsp-signature-help",
11 "L3MON4D3/LuaSnip", 11 "L3MON4D3/LuaSnip",
12 "saadparwaiz1/cmp_luasnip", 12 "saadparwaiz1/cmp_luasnip",
13 "rafamadriz/friendly-snippets", 13 "honza/vim-snippets",
14 }, 14 },
15 config = function() 15 config = function()
16 local cmp = require("cmp") 16 local cmp = require("cmp")
@@ -49,13 +49,10 @@ return {
49 ---@diagnostic disable-next-line: missing-fields 49 ---@diagnostic disable-next-line: missing-fields
50 cmp.setup({ 50 cmp.setup({
51 enabled = function() 51 enabled = function()
52 -- disable autocompletion in prompt 52 -- disable autocompletion in telescope prompt
53 local buftype = vim.api.nvim_buf_get_option(0, "buftype") 53 local buftype = vim.api.nvim_buf_get_option(0, "buftype")
54 if buftype == "prompt" then return false end
55 54
56 local context = require 'cmp.config.context' 55 return buftype ~= "prompt"
57 -- disable autocompletion in comments
58 return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment")
59 end, 56 end,
60 ---@diagnostic disable-next-line: missing-fields 57 ---@diagnostic disable-next-line: missing-fields
61 completion = { 58 completion = {
@@ -73,8 +70,6 @@ return {
73 mapping = cmp.mapping.preset.insert({ 70 mapping = cmp.mapping.preset.insert({
74 ["<C-f>"] = cmp.mapping.scroll_docs(-4), 71 ["<C-f>"] = cmp.mapping.scroll_docs(-4),
75 ["<C-d>"] = cmp.mapping.scroll_docs(4), 72 ["<C-d>"] = cmp.mapping.scroll_docs(4),
76 ["<C-k>"] = cmp.mapping.select_prev_item(),
77 ["<C-j>"] = cmp.mapping.select_next_item(),
78 ["<CR>"] = cmp.mapping.confirm({ 73 ["<CR>"] = cmp.mapping.confirm({
79 behavior = cmp.ConfirmBehavior.Replace, 74 behavior = cmp.ConfirmBehavior.Replace,
80 select = false, 75 select = false,
@@ -105,16 +100,19 @@ return {
105 -- kind icons 100 -- kind icons
106 vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) 101 vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
107 vim_item.menu = ({ 102 vim_item.menu = ({
108 nvim_lsp = "[lsp]", 103 nvim_lsp = "[ ]",
109 luasnip = "[snippet]", 104 nvim_lsp_signature_help = "[󰞋 ]",
110 buffer = "[buffer]", 105 omni = "[ ]",
111 path = "[path]", 106 luasnip = "[ ]",
107 buffer = "[󰮳 ]",
108 path = "[ ]",
112 })[entry.source.name] 109 })[entry.source.name]
113 return vim_item 110 return vim_item
114 end, 111 end,
115 }, 112 },
116 sources = { 113 sources = {
117 { name = "nvim_lsp" }, 114 { name = "nvim_lsp" },
115 { name = "nvim_lsp_signature_help" },
118 { name = "luasnip" }, 116 { name = "luasnip" },
119 { name = "buffer" }, 117 { name = "buffer" },
120 { name = "path" }, 118 { name = "path" },
@@ -128,40 +126,14 @@ return {
128 cmp_autopairs.on_confirm_done() 126 cmp_autopairs.on_confirm_done()
129 ) 127 )
130 128
131 ---@diagnostic disable-next-line: missing-fields
132 cmp.setup.filetype('gitcommit', {
133 sources = cmp.config.sources({
134 { name = 'git' },
135 }, {
136 { name = 'buffer' },
137 })
138 })
139
140 -- use buffer source for `/` .
141 ---@diagnostic disable-next-line: missing-fields
142 cmp.setup.cmdline('/', {
143 mapping = cmp.mapping.preset.cmdline(),
144 sources = {
145 { name = 'buffer' }
146 }
147 })
148
149 -- use cmdline & path source for ':' .
150 ---@diagnostic disable-next-line: missing-fields
151 cmp.setup.cmdline(':', {
152 mapping = cmp.mapping.preset.cmdline(),
153 sources = cmp.config.sources({
154 { name = 'path' }
155 }, {
156 { name = 'cmdline' }
157 })
158 })
159
160 -- use omnifunc in vimwiki to complete paths and tags 129 -- use omnifunc in vimwiki to complete paths and tags
161 ---@diagnostic disable-next-line: missing-fields 130 ---@diagnostic disable-next-line: missing-fields
162 cmp.setup.filetype('vimwiki', { 131 cmp.setup.filetype('vimwiki', {
163 sources = cmp.config.sources({ 132 sources = cmp.config.sources({
164 { name = 'omni' }, 133 { name = "omni" },
134 { name = "luasnip" },
135 { name = "buffer" },
136 { name = "path" },
165 option = { 137 option = {
166 disable_omnifuncs = {}, 138 disable_omnifuncs = {},
167 }, 139 },
@@ -169,4 +141,28 @@ return {
169 }) 141 })
170 end, 142 end,
171 }, 143 },
144 {
145 "L3MON4D3/LuaSnip",
146 event = "InsertEnter",
147 dependencies = {
148 "honza/vim-snippets",
149 },
150 build = "make install_jsregexp",
151 keys = {
152 {
153 "<C-l>",
154 function() require("luasnip").expand_or_jump() end,
155 mode = { "i", "s" },
156 },
157 },
158 opts = {
159 history = false,
160 region_check_events = 'InsertEnter',
161 delete_check_events = 'InsertLeave',
162 },
163 config = function(_, opts)
164 require("luasnip").setup(opts)
165 require("luasnip.loaders.from_snipmate").lazy_load()
166 end,
167 },
172} 168}