From 88f276a65baec6e3f586a05a7922e9c44892e68e Mon Sep 17 00:00:00 2001 From: bpc2003 Date: Fri, 16 May 2025 13:27:06 -0400 Subject: Add LSP support --- init.lua | 8 ++++++++ lazy-lock.json | 1 + lua/config/lazy.lua | 3 +++ lua/plugins/keybindings.lua | 40 ++++++++++++++++++++++++++++++++-------- lua/plugins/lspconfig.lua | 28 ++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 lua/plugins/lspconfig.lua diff --git a/init.lua b/init.lua index 5f2496e..aed4c35 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,14 @@ require("config.lazy") require("plugins.keybindings") +require("plugins.lspconfig") vim.cmd([[colorscheme gruvbox]]) +vim.cmd([[ + augroup LSP_SignatureHelp + autocmd! + autocmd InsertCharPre,TextChanged * lua vim.lsp.buf.signature_help() + augroup end +]]) + vim.wo.relativenumber = true vim.opt.clipboard = "unnamedplus" diff --git a/lazy-lock.json b/lazy-lock.json index ba149fd..245f528 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,5 +1,6 @@ { "gruvbox.nvim": { "branch": "main", "commit": "00e38a379bab3389e187b3953566d67d494dfddd" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "nvim-lspconfig": { "branch": "master", "commit": "ac1dfbe3b60e5e23a2cff90e3bd6a3bc88031a57" }, "nvim-treesitter": { "branch": "master", "commit": "066fd6505377e3fd4aa219e61ce94c2b8bdb0b79" } } diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index d3c4443..e839f8f 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -41,6 +41,9 @@ require("lazy").setup({ }) end }, + { + "neovim/nvim-lspconfig" + }, { "ellisonleao/gruvbox.nvim" }, diff --git a/lua/plugins/keybindings.lua b/lua/plugins/keybindings.lua index 4665e69..cb40552 100644 --- a/lua/plugins/keybindings.lua +++ b/lua/plugins/keybindings.lua @@ -1,13 +1,31 @@ --- buffer commands -vim.keymap.set('n', 't', ':tabnew', { noremap = true, silent = true }) +-- ============help menu============= +-- open help menu +vim.keymap.set('n', '', + ':!less '.. + '~/.config/nvim/lua/plugins/keybindings.lua', + { noremap = true, silent = true }) + +-- ==============tabs================ +-- open a new tab +vim.keymap.set('n', 't', ':tabnew', + { noremap = true, silent = true }) + +-- go to next tab vim.keymap.set('n', 'n', 'gt') + +-- go to previous tab vim.keymap.set('n', 'p', 'gT') --- terminal -vim.keymap.set('n', 'v', ':vertical term', { noremap = true, silent = true}) -vim.keymap.set('n', 'h', ':belowright term', { noremap = true, silent = true}) +-- =============terminals============ +-- create a vertically split terminal +vim.keymap.set('n', 'v', ':vertical term', + { noremap = true, silent = true}) --- lazy +-- create a horizontally split terminal +vim.keymap.set('n', 'h', ':belowright term', + { noremap = true, silent = true}) + +-- ===============Lazy=============== vim.keymap.set('n', 'l', ':Lazy', { noremap = true }) vim.keymap.set('n', 'lu', ':Lazy update', { noremap = true }) vim.keymap.set('n', 'ls', ':Lazy sync', { noremap = true }) @@ -18,10 +36,16 @@ vim.keymap.set('n', 'lr', ':Lazy restore', { noremap = true }) vim.keymap.set('n', 'lp', ':Lazy profile', { noremap = true }) vim.keymap.set('n', 'ld', ':Lazy debug', { noremap = true }) --- write commands +-- ============file commands========= +-- write vim.keymap.set('n', 's', ':w', { noremap = true }) + +-- write and quit vim.keymap.set('n', 'sq', ':wq', { noremap = true }) --- quit +-- ===========quitting=============== +-- safe quit vim.keymap.set('n', 'q', ':q', { silent = true }) + +-- unsafe quit vim.keymap.set('n', 'Q', ':q!', { silent = true}) diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..526c164 --- /dev/null +++ b/lua/plugins/lspconfig.lua @@ -0,0 +1,28 @@ +vim.diagnostic.config({ + virtual_text = true, + signs = true, + underline = true, + severity_sort = true, +}) + +vim.lsp.config['ccls'] = { + cmd = { 'ccls' }, + root_markers = { '.ccls-cache', '.ccls' }, + filetypes = { 'c', 'cpp', 'cc', 'h' }, +} + +vim.lsp.config['gopls'] = { + cmd = { 'gopls' }, + root_markers = { 'go.mod', 'go.work' }, + filetypes = { 'go' }, +} + +vim.lsp.config['rust_analyzer'] = { + cmd = { 'rust-analyzer' }, + root_markers = { 'Cargo.toml' }, + filetypes = { 'rs' }, +} + +vim.lsp.enable('ccls') +vim.lsp.enable('gopls') +vim.lsp.enable('rust_analyzer') -- cgit v1.2.3