From 109e3f7a6330bc40feefdc039ade121b2ad20d51 Mon Sep 17 00:00:00 2001 From: hwu Date: Tue, 13 Aug 2024 23:01:02 -0400 Subject: [PATCH] add function signatures and format short cuts --- init.lua | 43 +++++++++++++++++------------------- lua/custom/plugins/pairs.lua | 8 ++++++- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/init.lua b/init.lua index d29fecee..9fcf1408 100644 --- a/init.lua +++ b/init.lua @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` @@ -102,7 +102,7 @@ vim.g.have_nerd_font = false vim.opt.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.opt.mouse = 'a' @@ -146,7 +146,7 @@ vim.opt.splitbelow = true -- See `:help 'list'` -- and `:help 'listchars'` vim.opt.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣', eol = '¬' } -- Preview substitutions live, as you type! vim.opt.inccommand = 'split' @@ -161,8 +161,8 @@ vim.opt.scrolloff = 10 -- See `:help vim.keymap.set()` -- MY KEYMAPS BEGIN -vim.api.nvim_exec( - [[ +vim.api.nvim_exec2( + [[ function! s:ZoomToggle() abort if exists('t:zoomed') && t:zoomed execute t:zoom_winrestcmd @@ -176,19 +176,14 @@ vim.api.nvim_exec( endfunction command! ZoomToggle call s:ZoomToggle() ]], - false + { output = false } ) -vim.cmd [[ - set listchars=eol:¬ - " hi NonText guibg=#eee - nnoremap ,h (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" -]] +vim.keymap.set('n', ',h', [[ (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n"]], { silent = true, expr = true, desc = 'toggles highlighting' }) vim.keymap.set('n', ';', ':', { noremap = true, desc = 'Command mode' }) vim.keymap.set('n', "'", '`', { noremap = true, desc = 'Mark character' }) vim.keymap.set('n', '`', "'", { noremap = true, desc = 'Mark line' }) --- vim.keymap.set("n", "œ", "bdelete", { silent = true, desc = "Buffer Delete" }) vim.keymap.set('n', '', 'ZoomToggle', { noremap = true, desc = 'Zoom Toggle' }) vim.keymap.set('i', 'df', '', { noremap = true, desc = 'ESC' }) @@ -202,6 +197,9 @@ vim.keymap.set('n', ',N', 'Neotree reveal left', { noremap = true, desc vim.keymap.set('n', 'w', ':w', { noremap = true, desc = 'Save file' }) +vim.keymap.set('i', '', vim.lsp.buf.signature_help, { noremap = true, desc = 'Signature Help' }) +vim.keymap.set('n', 'ff', vim.lsp.buf.format, { noremap = true, desc = 'LSP format' }) + vim.g.diagnostics_active = false function _G.toggle_diagnostics() if vim.g.diagnostics_active then @@ -342,6 +340,7 @@ require('lazy').setup({ { 'd', group = '[D]ocument' }, { 'r', group = '[R]ename' }, { 's', group = '[S]earch' }, + { 'f', group = '[F]ormat' }, { 'w', group = '[W]orkspace' }, { 't', group = '[T]oggle' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, @@ -521,6 +520,7 @@ require('lazy').setup({ -- Allows extra capabilities provided by nvim-cmp 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-nvim-lsp-signature-help', }, config = function() -- Brief aside: **What is LSP?** @@ -630,16 +630,6 @@ require('lazy').setup({ }) end - -- custom auto format - if client then - client.server_capabilities.documentFormattingProvider = true - vim.api.nvim_create_autocmd('BufWritePre', { - callback = function() - vim.lsp.buf.format() - end, - }) - end - -- The following code creates a keymap to toggle inlay hints in your -- code, if the language server you are using supports them -- @@ -838,7 +828,13 @@ require('lazy').setup({ -- Accept ([y]es) the completion. -- This will auto-import if your LSP supports it. -- This will expand snippets if the LSP sent a snippet. - [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm { select = true } + else + cmp.complete() + end + end, { 'i', 's' }), -- If you prefer more traditional completion keymaps, -- you can uncomment the following lines @@ -880,6 +876,7 @@ require('lazy').setup({ group_index = 0, }, { name = 'nvim_lsp' }, + { name = 'nvim_lsp_signature_help' }, { name = 'luasnip' }, { name = 'path' }, }, diff --git a/lua/custom/plugins/pairs.lua b/lua/custom/plugins/pairs.lua index d4d2c617..85202cae 100644 --- a/lua/custom/plugins/pairs.lua +++ b/lua/custom/plugins/pairs.lua @@ -1,7 +1,13 @@ return { 'windwp/nvim-autopairs', event = 'InsertEnter', - config = true, + -- config = true, -- use opts = {} for passing setup options -- this is equalent to setup({}) function + config = function() + require('nvim-autopairs').setup {} + local cmp_autopairs = require 'nvim-autopairs.completion.cmp' + local cmp = require 'cmp' + cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) + end, }