commit c5000e27eb36acba4bc0c238918f2d3d40a2a463 Author: Louis Hollingworth Date: Sat Mar 2 13:31:01 2024 +0000 New neovim config. I've been using neovim for a while but the config got messy so here is a cleaner config. Signed-off-by: Louis Hollingworth diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua new file mode 100644 index 0000000..63bffa4 --- /dev/null +++ b/after/plugin/lsp.lua @@ -0,0 +1,135 @@ +local keymap = vim.keymap.set + +require('mason').setup({ + ui = { + icons = { + server = " ", + lsp = " ", + linter = " ", + formatter = " ", + + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + }, + }, +}) + +require("mason-lspconfig").setup({ + automatic_installation = true, +}) + +local lsp = require('lspconfig') + +local cmp = require('cmp') +local cmp_select = {behavior = cmp.SelectBehavior.Select} + +local opts = { noremap=true, silent=true } +--keymap('i', '', vim.diagnostic.open_float, opts) +--keymap('i', '', vim.diagnostic.goto_prev, opts) +--keymap('i', '', vim.diagnostic.goto_next, opts) +--keymap('i', '', cmp.mapping.complete(), opts) +--keymap('i', '', vim.diagnostic.setloclist, opts) +keymap('n', '', vim.diagnostic.open_float, opts) +keymap('n', '', vim.diagnostic.goto_prev, opts) +keymap('n', '', vim.diagnostic.goto_next, opts) +--keymap('i', '', cmp.mapping.complete(), opts) +keymap('n', '', vim.diagnostic.setloclist, opts) + +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.complete(cmp_select), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'buffer' }, + }, +}) + +vim.diagnostic.config({ + virtual_text = true, +}) + +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + + -- Mappings. + local opts = { noremap = true, silent = true, buffer = bufnr} + + -- See `:help vim.lsp.*` for documentation on any of the below functions + vim.keymap.set("n", "gd", "Telescope lsp_definitions", opts) + vim.keymap.set("n", "gr", "Telescope lsp_references", opts) + + vim.keymap.set("n", "", "Telescope lsp_document_symbols", opts) + vim.keymap.set("n", "", "lua vim.lsp.buf.signature_help()", opts) + + vim.keymap.set("n", "gi", "Telescope lsp_implementations", opts) + vim.keymap.set("n", "K", "lua vim.lsp.buf.hover()", opts) + vim.keymap.set("n", "D", "Telescope lsp_type_definitions", opts) + vim.keymap.set("n", "rn", "lua vim.lsp.buf.rename()", opts) + vim.keymap.set("n", "ca", "Telescope lsp_code_actions", opts) + vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, {buffer=0}) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {buffer=0}) + vim.keymap.set("n", "dj", vim.diagnostic.goto_next, {buffer=0}) + vim.keymap.set("n", "dk", vim.diagnostic.goto_prev, {buffer=0}) + vim.keymap.set("n", "dl", "Telescope diagnostics", {buffer=0}) + vim.keymap.set("n", "r", vim.lsp.buf.rename, {buffer=0}) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, {buffer=0}) + + -- Set autocommands conditional on server_capabilities + if client.server_capabilities.document_highlight then + vim.cmd([[ + augroup lsp_document_highlight + autocmd! * + autocmd CursorHold lua vim.lsp.buf.document_highlight() + autocmd CursorMoved lua vim.lsp.buf.clear_references() + augroup END + ]]) + end +end + +lsp.gopls.setup({ + on_attach = on_attach, + flags = lsp_flags, + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = true, + }, + }, +}) + +lsp['lua_ls'].setup{ + on_attach = on_attach, + flags = lsp_flags, +} + +lsp['rust_analyzer'].setup{ + on_attach = on_attach, + flags = lsp_flags, + cmd = { + "rustup", "run", "stable", "rust-analyzer", + } +} + +lsp.tsserver.setup{ + on_attach = on_attach, + flags = lsp_flags, +} diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..884e86d --- /dev/null +++ b/init.lua @@ -0,0 +1 @@ +require("lucxjo") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..b9c2533 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,31 @@ +{ + "LuaSnip": { "branch": "master", "commit": "f3b3d3446bcbfa62d638b1903ff00a78b2b730a1" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "editorconfig-vim": { "branch": "master", "commit": "0956bc257ca4eaa3e087e0ba2253a3e980805820" }, + "formatter.nvim": { "branch": "master", "commit": "cb4778b8432f1ae86dae4634c0b611cb269a4c2f" }, + "friendly-snippets": { "branch": "main", "commit": "dcd4a586439a1c81357d5b9d26319ae218cc9479" }, + "glow.nvim": { "branch": "main", "commit": "238070a686c1da3bccccf1079700eb4b5e19aea4" }, + "lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" }, + "lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, + "lspsaga.nvim": { "branch": "main", "commit": "b1b140aa20a0cf353cd3e282870429b48b30a169" }, + "lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "21d33d69a81f6351e5a5f49078b2e4f0075c8e73" }, + "mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" }, + "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, + "nvim-dap": { "branch": "master", "commit": "fc880e82059eb21c0fa896be60146e5f17680648" }, + "nvim-dap-ui": { "branch": "master", "commit": "9720eb5fa2f41988e8770f973cd11b76dd568a5d" }, + "nvim-lint": { "branch": "master", "commit": "e824adb9bc01647f71e55457353a68f0f37f9931" }, + "nvim-lspconfig": { "branch": "master", "commit": "9553725789be682ecd945a527ec552e489ea8534" }, + "nvim-treesitter": { "branch": "master", "commit": "a47540fd737eb5c03ee21ee69eb8134ce5568fb6" }, + "nvim-web-devicons": { "branch": "master", "commit": "0bb67ef952ea3eb7b1bac9c011281471d99a27bc" }, + "plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, + "telescope.nvim": { "branch": "master", "commit": "aa83606299c5beeaf80e656efbf07bde258db7be" }, + "todo-comments.nvim": { "branch": "main", "commit": "833d8dd8b07eeda37a09e99460f72a02616935cb" }, + "tokyonight.nvim": { "branch": "main", "commit": "610179f7f12db3d08540b6cc61434db2eaecbcff" }, + "undotree": { "branch": "master", "commit": "9dbbf3b7d19dda0d22ceca461818e4739ad8154d" }, + "vim-wakatime": { "branch": "master", "commit": "285c2e4e48fb0c63ced233c00fb10a2edb3b6c94" } +} \ No newline at end of file diff --git a/lua/lucxjo/init.lua b/lua/lucxjo/init.lua new file mode 100644 index 0000000..15a5b2e --- /dev/null +++ b/lua/lucxjo/init.lua @@ -0,0 +1,43 @@ +require("lucxjo.keys") +require("lucxjo.lazy") +require("lucxjo.opts") + +local augroup = vim.api.nvim_create_augroup +local lucxjo_group = augroup('lucxjo', {}) + +local aucmd = vim.api.nvim_create_autocmd +local yank_group = augroup('HlYank', {}) + +aucmd('TextYankPost', { + group = yank_group, + pattern = '*', + callback = function() + vim.highlight.on_yank({ + higroup = 'IncSearch', + timeout = 40, + }) + end, +}) + +aucmd({"BufWritePre"}, { + group = lucxjo_group, + pattern = "*", + command = [[%s/\s\+$//e]], +}) + +aucmd('LspAttach', { + group = lucxjo, + callback = function(e) + local opts = { buffer = e.buf } + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + end +}) diff --git a/lua/lucxjo/keys.lua b/lua/lucxjo/keys.lua new file mode 100644 index 0000000..8b8040b --- /dev/null +++ b/lua/lucxjo/keys.lua @@ -0,0 +1,13 @@ +vim.g.mapleader = " " + +local map = vim.api.nvim_set_keymap + +map("n", "p", ":Glow", {}) +map("n", "ch", ":nohl", { silent = true }) + +-- File management +map("n", "s", ":w", { silent = true}) +map("n", "q", ":q", {}) +map("n", "Q", ":q!", {}) +map("n", "S", ":wq", {}) +map("n", "fp", ":Ex", {}) diff --git a/lua/lucxjo/lazy.lua b/lua/lucxjo/lazy.lua new file mode 100644 index 0000000..8072885 --- /dev/null +++ b/lua/lucxjo/lazy.lua @@ -0,0 +1,14 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup("lucxjo.plugins") diff --git a/lua/lucxjo/opts.lua b/lua/lucxjo/opts.lua new file mode 100644 index 0000000..3f70dd6 --- /dev/null +++ b/lua/lucxjo/opts.lua @@ -0,0 +1,39 @@ +local opt = vim.opt + +-- Context +opt.colorcolumn = "80" +opt.number = true +opt.relativenumber = true +opt.scrolloff = 4 +opt.signcolumn = "yes" + +-- Filetypes +opt.encoding = "utf8" +opt.fileencoding = "utf8" + +-- Theme +opt.syntax = "ON" +opt.termguicolors = true + +-- Search +opt.ignorecase = true +opt.smartcase = true +opt.incsearch = true +opt.hlsearch = true + +-- Whitespace +opt.expandtab = true +opt.shiftwidth = 4 +opt.softtabstop = 4 +opt.tabstop = 4 +opt.smartindent = true + +-- Undo +opt.undodir = os.getenv("HOME") .. "/.vim/undodir" +opt.undofile = true + +-- Misc +opt.backspace = "indent,eol,start" +opt.clipboard:append("unnamedplus") +opt.iskeyword:append("-") +vim.cmd[[colorscheme tokyonight]] diff --git a/lua/lucxjo/plugins/init.lua b/lua/lucxjo/plugins/init.lua new file mode 100644 index 0000000..4d1e9e0 --- /dev/null +++ b/lua/lucxjo/plugins/init.lua @@ -0,0 +1,32 @@ +return { + { + "folke/tokyonight.nvim", + lazy = false, + priority = 1000, + opts = { + transparent = true, + }, + }, + "editorconfig/editorconfig-vim", + { + "ellisonleao/glow.nvim", + config = function() require("glow").setup() end, + }, + { + "nvim-lualine/lualine.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() require("lualine").setup{ + options = { + theme = "tokyonight", + }, + } end, + }, + "wakatime/vim-wakatime", + { + "folke/todo-comments.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = {}, + }, + "nvim-tree/nvim-web-devicons", + "mbbill/undotree", +} diff --git a/lua/lucxjo/plugins/lsp.lua b/lua/lucxjo/plugins/lsp.lua new file mode 100644 index 0000000..c80f666 --- /dev/null +++ b/lua/lucxjo/plugins/lsp.lua @@ -0,0 +1,57 @@ +return { + -- Autocomplete + "hrsh7th/nvim-cmp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + + -- Snippets + { + "L3MON4D3/LuaSnip", + build = "make install_jsregexp", + }, + "saadparwaiz1/cmp_luasnip", + "rafamadriz/friendly-snippets", + + -- Manage + { + "williamboman/mason.nvim", + config = function() require("mason").setup() end, + }, + { + "williamboman/mason-lspconfig.nvim", + config = function() require("mason-lspconfig").setup() end, + }, + + -- Configure + "neovim/nvim-lspconfig", + "hrsh7th/cmp-nvim-lsp", + "glepnir/lspsaga.nvim", + "onsails/lspkind.nvim", + + -- Lint + { + "mfussenegger/nvim-lint", + config = function() + require("lint").linters_by_ft = { + go = {'golangclient'}, + lua = {'luacheck'}, + sh = {'shellcheck'}, + c = {'cpplint'} + } + end, + }, + + -- Format + { + "mhartington/formatter.nvim", + config = function() + require("formatter").setup() + end, + }, + + -- DAP + { + "rcarriga/nvim-dap-ui", + dependencies = {"mfussenegger/nvim-dap"} + }, +} diff --git a/lua/lucxjo/plugins/telescope.lua b/lua/lucxjo/plugins/telescope.lua new file mode 100644 index 0000000..ad9b155 --- /dev/null +++ b/lua/lucxjo/plugins/telescope.lua @@ -0,0 +1,20 @@ +return { + { + 'nvim-telescope/telescope.nvim', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-telescope/telescope-fzf-native.nvim', + }, + config = function() + local builtin = require('telescope.builtin') + vim.keymap.set('n', 'ff', builtin.find_files, {}) + vim.keymap.set('n', 'fg', builtin.live_grep, {}) + vim.keymap.set('n', 'fb', builtin.buffers, {}) + vim.keymap.set('n', 'fh', builtin.help_tags, {}) + end, + }, + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' + }, +} diff --git a/lua/lucxjo/plugins/treesitter.lua b/lua/lucxjo/plugins/treesitter.lua new file mode 100644 index 0000000..74d8d55 --- /dev/null +++ b/lua/lucxjo/plugins/treesitter.lua @@ -0,0 +1,4 @@ +return { + "nvim-treesitter/nvim-treesitter", + config = function() require('nvim-treesitter.install').update({ with_sync = true }) end, +}