From 6d3c813c2b3320f35cc7845021f4b4a1636c8eeb Mon Sep 17 00:00:00 2001 From: Citlali del Rey Date: Wed, 29 Nov 2023 16:16:03 -0800 Subject: [PATCH] setup luasnip better --- nvim/init.vim | 16 ++++++++++------ nvim/lua/lsp.lua | 42 ++++++++++++++++++++++++++++++++++++++---- nvim/lua/plugins.lua | 19 +++++++++++++++++-- 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/nvim/init.vim b/nvim/init.vim index ca4fe33..f7d5799 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -1,4 +1,5 @@ let g:mapleader = "," +let g:maplocalleader = "," lua require('plugins') lua require('lsp') @@ -21,9 +22,9 @@ tnoremap wincmd l " Terminal command Terminal below 15sp term://$SHELL |startinsert -autocmd TermOpen * set nonu autocmd BufEnter term://* startinsert autocmd BufLeave term://* stopinsert +autocmd TermOpen * setlocal nonumber norelativenumber signcolumn=no nnoremap Terminal @@ -56,7 +57,7 @@ set background=light set completeopt=menu,menuone,noselect set tabstop=4 set shiftwidth=0 -set number relativenumber +set number relativenumber signcolumn=yes set mouse=a set cursorline set noexpandtab @@ -89,12 +90,12 @@ let g:neovide_floating_blur_amount_x = 2.0 let g:neovide_floating_blur_amount_y = 2.0 let g:neovide_floating_opacity = 60 -set guifont=SFMono\ Nerd\ Font +set guifont=0xProto\ Nerd\ Font,Symbols\ Nerd\ Font\ Mono -sign define DiagnosticSignError text= texthl=DiagnosticSignError linehl= numhl=DiagnosticSignError -sign define DiagnosticSignWarn text= texthl=DiagnosticSignWarn linehl= numhl=DiagnosticSignWarn +sign define DiagnosticSignError text= texthl=DiagnosticSignError linehl= numhl=DiagnosticSignError +sign define DiagnosticSignWarn text= texthl=DiagnosticSignWarn linehl= numhl=DiagnosticSignWarn sign define DiagnosticSignInfo text= texthl=DiagnosticSignInfo linehl= numhl=DiagnosticSignInfo -sign define DiagnosticSignHint text= texthl=DiagnosticSignHint linehl= numhl=DiagnosticSignHint +sign define DiagnosticSignHint text= texthl=DiagnosticSignHint linehl= numhl=DiagnosticSignHint " Trouble nnoremap xx TroubleToggle @@ -109,3 +110,6 @@ nnoremap ff Telescope find_files nnoremap fg Telescope live_grep nnoremap fb Telescope buffers nnoremap fh Telescope help_tags + +filetype plugin on +filetype indent on diff --git a/nvim/lua/lsp.lua b/nvim/lua/lsp.lua index 3a0904b..c1f82f4 100644 --- a/nvim/lua/lsp.lua +++ b/nvim/lua/lsp.lua @@ -31,7 +31,7 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', 'f', function() + vim.keymap.set('n', 'fm', function() vim.lsp.buf.format({ async = true }) end, bufopts) @@ -61,7 +61,12 @@ local cmp = require('cmp') local luasnip = require('luasnip') local lspkind = require('lspkind') -cmp.setup({ +luasnip.config.set_config { + region_check_events = {'CursorMoved', 'InsertEnter'}, + delete_check_events = {'TextChanged', 'InsertLeave'}, +} + +cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) @@ -69,7 +74,7 @@ cmp.setup({ }, window = { -- completion = cmp.config.window.bordered(), - -- documentation = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), @@ -77,6 +82,30 @@ cmp.setup({ [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping(function(fallback) + if luasnip.expandable() then + luasnip.expand() + elseif cmp.visible() then + if #cmp.get_entries() == 1 then + cmp.confirm({ select = true}) + else + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + end + elseif luasnip.locally_jumpable() then + luasnip.jump() + else + fallback() + end + end, {"i", "s", "c"}), + [''] = cmp.mapping(function (fallback) + if cmp.visible() then + cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, {"i", "s", "c"}), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, @@ -92,7 +121,7 @@ cmp.setup({ maxwidth = 50, }), }, -}) +} cmp.setup.cmdline('/', { mapping = cmp.mapping.preset.cmdline(), @@ -133,3 +162,8 @@ mason_lspconfig.setup_handlers { lspconfig[server_name].setup {} end, } + + +-- Load all snippets from the nvim/LuaSnip directory at startup +require("luasnip.loaders.from_lua").load() + diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 46f9faf..b2af4c6 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -151,6 +151,10 @@ require('lualine').setup { }, winbar = { "help", + "terminal", + "TERMINAL", + "fish", + "term", "startify", "dashboard", "packer", @@ -176,7 +180,18 @@ require('lualine').setup { }, sections = { lualine_a = { 'mode' }, - lualine_b = { 'diff', 'diagnostics' }, + lualine_b = { + 'diff', + { + 'diagnostics', + symbols = { + error = ' ', + warn = ' ', + info = ' ', + hint = ' ', + }, + }, + }, lualine_c = { 'filename' }, lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_y = { 'progress' }, @@ -203,7 +218,7 @@ require('lualine').setup { lualine_c = { 'hostname' }, lualine_x = {}, lualine_y = {}, - lualine_z = { 'tabs', 'datetime' }, + lualine_z = { 'tabs', { 'datetime', style = 'iso' } }, }, winbar = { lualine_a = { 'searchcount' },