diff options
| author | Jean-Pierre Appel <jeanpierre.appel01@gmail.com> | 2023-08-27 22:15:00 -0400 |
|---|---|---|
| committer | Jean-Pierre Appel <jeanpierre.appel01@gmail.com> | 2023-08-27 22:15:00 -0400 |
| commit | e61cea38a6f3d35a389d9236e632b0eeb14fa788 (patch) | |
| tree | 7d36ffeb741d8472bfd77ba1e07a6fa0f6336fa0 /nvim/lua | |
| parent | effbea32afb26f365d81a5797b9c24bc6fd1aa81 (diff) | |
added completions for some languages
Diffstat (limited to 'nvim/lua')
| -rw-r--r-- | nvim/lua/colorscheme.lua | 0 | ||||
| -rw-r--r-- | nvim/lua/lsp.lua | 11 | ||||
| -rw-r--r-- | nvim/lua/plugins/colorscheme.lua | 33 | ||||
| -rw-r--r-- | nvim/lua/plugins/init.lua | 6 | ||||
| -rw-r--r-- | nvim/lua/plugins/nvim-cmp.lua | 216 |
5 files changed, 253 insertions, 13 deletions
diff --git a/nvim/lua/colorscheme.lua b/nvim/lua/colorscheme.lua deleted file mode 100644 index e69de29..0000000 --- a/nvim/lua/colorscheme.lua +++ /dev/null diff --git a/nvim/lua/lsp.lua b/nvim/lua/lsp.lua index cac88ef..1a45349 100644 --- a/nvim/lua/lsp.lua +++ b/nvim/lua/lsp.lua @@ -4,9 +4,13 @@ lsp.preset({}) lsp.ensure_installed({ 'pylsp', - 'gopls', + 'html', + -- 'java_language_server', + -- 'ltex', + 'lua_ls', + --'gopls', 'tsserver', - 'rust_analyzer' + --'rust_analyzer' }) lsp.on_attach(function(client, bufnr) @@ -19,6 +23,9 @@ lsp.set_preferences({ sign_icons = { } }) + +-- LS configs +-- require('lspconfig').lua_ls.setup(lsp.nvim_lua_ls()) diff --git a/nvim/lua/plugins/colorscheme.lua b/nvim/lua/plugins/colorscheme.lua index 6df2325..f225789 100644 --- a/nvim/lua/plugins/colorscheme.lua +++ b/nvim/lua/plugins/colorscheme.lua @@ -1,12 +1,23 @@ -return { - { - "catppuccin/nvim" , - name = "catpuccin", - enabled = true, - lazy = false, - priority = 1000, - config = function() - vim.cmd("colorscheme catppuccin-mocha") - end - }, +local colorscheme = { + lazy = false, + priority = 1000 } + +local catpuccin = { + "catppuccin/nvim" , + name = "catpuccin", + config = function() + vim.cmd[[colorscheme catppuccin-mocha]] + end +} + +local tokyonight = { + 'folke/tokyonight.nvim', + name = 'tokyonight', + config = function() + vim.cmd[[colorscheme tokyonight-night]] + end +} + +-- combine default colorscheme settings with selected theme +return vim.tbl_extend('force', colorscheme, catpuccin) diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua index 8628e2e..d9c31dd 100644 --- a/nvim/lua/plugins/init.lua +++ b/nvim/lua/plugins/init.lua @@ -29,6 +29,12 @@ return { { 'numToStr/Comment.nvim', -- faster commentting lazy = false, + opts = { + mappings = { + basic = true, + extra = false + } + }, -- config = function() -- require('Comment').setup() -- end diff --git a/nvim/lua/plugins/nvim-cmp.lua b/nvim/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..907ba2e --- /dev/null +++ b/nvim/lua/plugins/nvim-cmp.lua @@ -0,0 +1,216 @@ +-- modified from https://github.com/VonHeikemen/dotfiles + +local Plugins = {} + +-- Autocompletion +local cmp_plugin = { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + -- Sources + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'saadparwaiz1/cmp_luasnip', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-nvim-lua', + + -- Snippets + {'L3MON4D3/LuaSnip'}, + } +} + +local user = {autocomplete = true} + +table.insert(Plugins, cmp_plugin) + +table.insert(Plugins, { + 'aspeddro/cmp-pandoc.nvim', + enabled = false, + event = 'InsertEnter', + ft = {'markdown', 'pandoc', 'rmd'}, + dependencies = { + 'nvim-lua/plenary.nvim', + 'jbyuki/nabla.nvim' + }, + opts = { + crossref = { + enable_nabla = true + } + } +}) + +function cmp_plugin.config() + user.augroup = vim.api.nvim_create_augroup('compe_cmds', {clear = true}) + vim.api.nvim_create_user_command('UserCmpEnable', user.enable_cmd, {}) + + local cmp = require('cmp') + local luasnip = require('luasnip') + + local select_opts = {behavior = cmp.SelectBehavior.Select} + local cmp_enable = cmp.get_config().enabled + + user.config = { + enabled = function() + if user.autocomplete then + return cmp_enable() + end + + return false + end, + completion = { + completeopt = 'menu,menuone', + }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, + {name = 'cmp_pandoc' }, + }, + window = { + documentation = { + border = 'rounded', + max_height = 15, + max_width = 50, + zindex = 50, + } + }, + -- formatting = { + -- fields = {'menu', 'abbr', 'kind'}, + -- format = function(entry, item) + -- local menu_icon = { + -- nvim_lsp = 'λ', + -- luasnip = '⋗', + -- buffer = 'Ω', + -- path = '🖫', + -- nvim_lua = 'Π', + -- } + -- + -- item.menu = menu_icon[entry.source.name] + -- return item + -- end, + -- }, + mapping = { + ['<C-k>'] = cmp.mapping.scroll_docs(-5), + ['<C-j>'] = cmp.mapping.scroll_docs(5), + + ['<Up>'] = cmp.mapping.select_prev_item(select_opts), + ['<Down>'] = cmp.mapping.select_next_item(select_opts), + + -- TODO: test + -- ['<M-k>'] = cmp.mapping.select_prev_item(select_opts), + -- ['<M-j>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-a>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, {'i', 's'}), + + ['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, {'i', 's'}), + + ['<M-u>'] = cmp.mapping(function() + if cmp.visible() then + user.set_autocomplete(false) + cmp.abort() + else + user.set_autocomplete(true) + cmp.complete() + end + end), + + ['<Tab>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm({select = true}) + elseif luasnip.jumpable(1) then + luasnip.jump(1) + elseif user.check_back_space() then + fallback() + else + user.set_autocomplete(true) + cmp.complete() + end + end, {'i', 's'}), + + ['<S-Tab>'] = cmp.mapping(function() + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + user.insert_tab() + end + end, {'i', 's'}), + } + } + + cmp.setup(user.config) +end + +function user.set_autocomplete(new_value) + local old_value = user.autocomplete + + if new_value == old_value then + return + end + + if new_value == false then + -- restore autocomplete in the next word + vim.api.nvim_buf_set_keymap( + 0, + 'i', + '<space>', + '<cmd>UserCmpEnable<cr><space>', + {noremap = true} + ) + + -- restore when leaving insert mode + vim.api.nvim_create_autocmd('InsertLeave', { + group = user.augroup, + command = 'UserCmpEnable', + once = true, + }) + end + + user.autocomplete = new_value +end + + +function user.check_back_space() + local col = vim.fn.col('.') - 1 + if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + return true + else + return false + end +end + +function user.enable_cmd() + if user.autocomplete then + return + end + + pcall(vim.api.nvim_buf_del_keymap, 0, 'i', '<Space>') + user.set_autocomplete(true) +end + +function user.insert_tab() + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes('<Tab>', true, true, true), + 'n', + true + ) +end + +return Plugins |
