From 2537f12e0c49c3c25a5a93b8f562fae11c4aab46 Mon Sep 17 00:00:00 2001 From: David Ibia Date: Mon, 1 Jan 2024 12:34:19 +0100 Subject: [PATCH] feat: added neovim configuration --- init.lua | 1 + lazy-lock.json | 27 ++++++++++ lua/absolute/after/harpoon.lua | 10 ++++ lua/absolute/after/lsp-zero.lua | 51 +++++++++++++++++++ lua/absolute/after/nvim-cmp.lua | 32 ++++++++++++ lua/absolute/after/nvim-tree.lua | 47 +++++++++++++++++ lua/absolute/after/nvim-treesitter.lua | 22 ++++++++ lua/absolute/after/rose-pine.lua | 4 ++ lua/absolute/after/telescope.lua | 6 +++ lua/absolute/after/undotree.lua | 1 + lua/absolute/after/vim-fugitive.lua | 1 + lua/absolute/core/init.lua | 33 ++++++++++++ lua/absolute/init.lua | 3 ++ lua/absolute/lazy.lua | 14 +++++ lua/absolute/plugins/copilot.lua | 3 ++ lua/absolute/plugins/harpoon.lua | 7 +++ lua/absolute/plugins/lsp-zero.lua | 15 ++++++ lua/absolute/plugins/nvim-cmp.lua | 17 +++++++ lua/absolute/plugins/nvim-tree.lua | 7 +++ .../plugins/nvim-treesitter-playground.lua | 6 +++ lua/absolute/plugins/nvim-treesitter.lua | 7 +++ lua/absolute/plugins/rose-pine.lua | 7 +++ lua/absolute/plugins/telescope.lua | 16 ++++++ lua/absolute/plugins/undotree.lua | 6 +++ lua/absolute/plugins/vim-fugitive.lua | 7 +++ lua/absolute/plugins/vim-tmux-navigator.lua | 17 +++++++ lua/absolute/remap.lua | 35 +++++++++++++ 27 files changed, 402 insertions(+) create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/absolute/after/harpoon.lua create mode 100644 lua/absolute/after/lsp-zero.lua create mode 100644 lua/absolute/after/nvim-cmp.lua create mode 100644 lua/absolute/after/nvim-tree.lua create mode 100644 lua/absolute/after/nvim-treesitter.lua create mode 100644 lua/absolute/after/rose-pine.lua create mode 100644 lua/absolute/after/telescope.lua create mode 100644 lua/absolute/after/undotree.lua create mode 100644 lua/absolute/after/vim-fugitive.lua create mode 100644 lua/absolute/core/init.lua create mode 100644 lua/absolute/init.lua create mode 100644 lua/absolute/lazy.lua create mode 100644 lua/absolute/plugins/copilot.lua create mode 100644 lua/absolute/plugins/harpoon.lua create mode 100644 lua/absolute/plugins/lsp-zero.lua create mode 100644 lua/absolute/plugins/nvim-cmp.lua create mode 100644 lua/absolute/plugins/nvim-tree.lua create mode 100644 lua/absolute/plugins/nvim-treesitter-playground.lua create mode 100644 lua/absolute/plugins/nvim-treesitter.lua create mode 100644 lua/absolute/plugins/rose-pine.lua create mode 100644 lua/absolute/plugins/telescope.lua create mode 100644 lua/absolute/plugins/undotree.lua create mode 100644 lua/absolute/plugins/vim-fugitive.lua create mode 100644 lua/absolute/plugins/vim-tmux-navigator.lua create mode 100644 lua/absolute/remap.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..35741cf --- /dev/null +++ b/init.lua @@ -0,0 +1 @@ +require("absolute") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..aa9601f --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,27 @@ +{ + "LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "copilot.vim": { "branch": "release", "commit": "5b19fb001d7f31c4c7c5556d7a97b243bd29f45f" }, + "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, + "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "81c25389c855dd0e0fad4863f7464e1389e45ca3" }, + "lspkind.nvim": { "branch": "master", "commit": "7f26cf5e27e2bd910ce0ea00c514da2bf97423b8" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "56e435e09f8729af2d41973e81a0db440f8fe9c9" }, + "mason.nvim": { "branch": "main", "commit": "a09da6ac634926a299dd439da08bdb547a8ca011" }, + "nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" }, + "nvim-lspconfig": { "branch": "master", "commit": "9bedcfed749755e43fc8bed46f85ce2044fe3b77" }, + "nvim-tree.lua": { "branch": "master", "commit": "f1b3e6a7eb92da492bd693257367d9256839ed3d" }, + "nvim-treesitter": { "branch": "master", "commit": "e49f1e8ef3e8450a8446cb1f2bbb53c919f60b6d" }, + "nvim-web-devicons": { "branch": "master", "commit": "cff25ce621e6d15fae0b0bfe38c00be50ce38468" }, + "playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" }, + "plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" }, + "rose-pine": { "branch": "main", "commit": "92762f4fa2144c05db760ea254f4c399a56a7ef5" }, + "telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, + "undotree": { "branch": "master", "commit": "36ff7abb6b60980338344982ad4cdf03f7961ecd" }, + "vim-fugitive": { "branch": "master", "commit": "59659093581aad2afacedc81f009ed6a4bfad275" }, + "vim-tmux-navigator": { "branch": "master", "commit": "38b1d0402c4600543281dc85b3f51884205674b6" } +} \ No newline at end of file diff --git a/lua/absolute/after/harpoon.lua b/lua/absolute/after/harpoon.lua new file mode 100644 index 0000000..56b2c25 --- /dev/null +++ b/lua/absolute/after/harpoon.lua @@ -0,0 +1,10 @@ +local mark = require("harpoon.mark") +local ui = require("harpoon.ui") + +vim.keymap.set("n", "a", mark.add_file) +vim.keymap.set("n", "", ui.toggle_quick_menu) + +vim.keymap.set("n", "", function() ui.nav_file(1) end) +vim.keymap.set("n", "", function() ui.nav_file(2) end) +vim.keymap.set("n", "", function() ui.nav_file(3) end) +vim.keymap.set("n", "", function() ui.nav_file(4) end) diff --git a/lua/absolute/after/lsp-zero.lua b/lua/absolute/after/lsp-zero.lua new file mode 100644 index 0000000..6222d62 --- /dev/null +++ b/lua/absolute/after/lsp-zero.lua @@ -0,0 +1,51 @@ +local lsp = require('lsp-zero') + + +require("mason").setup(); +require("mason-lspconfig").setup({ + ensure_installed = { + "tsserver", + "eslint", + "rust_analyzer" + }, +}) + + +lsp.preset("recommended") + + +local cmp = require("cmp") +local cmp_select = {behavior = cmp.SelectBehavior.Select} +local cmp_mappings = lsp.defaults.cmp_mappings({ + [""] = cmp.mapping.select_prev_item(cmp_select), + [""] = cmp.mapping.select_next_item(cmp_select), + [""] = cmp.mapping.confirm({select = true}), + [""] = cmp.mapping.complete(), +}) + + + +lsp.set_preferences({ + sign_icons = { } +}) + + +lsp.on_attach(function(client, bufnr) + local opts = {buffer = bufnr, remap = false} + + 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.lsp.buf.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.lsp.buf.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.lsp.buf.goto_prev() 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) + + +end) + + +lsp.setup() diff --git a/lua/absolute/after/nvim-cmp.lua b/lua/absolute/after/nvim-cmp.lua new file mode 100644 index 0000000..a4be42f --- /dev/null +++ b/lua/absolute/after/nvim-cmp.lua @@ -0,0 +1,32 @@ +local cmp = require("cmp") +local luasnip = require("luasnip") +local lspkind = require("lspkind") + + -- loads vscode style snippets from installed plugins (e.g. friendly-snippets) +require("luasnip.loaders.from_vscode").lazy_load() + +cmp.setup({ + + completion = { + completeopt = "menu,menuone,preview,noselect", + }, + snippet = { -- configure how nvim-cmp interacts with snippet engine + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + -- sources for autocompletion + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, -- snippets + { name = "buffer" }, -- text within current buffer + { name = "path" }, -- file system paths + }), + -- configure lspkind for vs-code like pictograms in completion menu + formatting = { + format = lspkind.cmp_format({ + maxwidth = 50, + ellipsis_char = "...", + }), + }, + }) diff --git a/lua/absolute/after/nvim-tree.lua b/lua/absolute/after/nvim-tree.lua new file mode 100644 index 0000000..8c5d34a --- /dev/null +++ b/lua/absolute/after/nvim-tree.lua @@ -0,0 +1,47 @@ +local nvimtree = require("nvim-tree") + +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +vim.cmd([[ highlight NvimTreeIndentMarker guifg=#3FC5FF ]]) + +vim.cmd([[ highlight NvimTreeFolderArrowClosed guifg=#3FC5FF ]]) +vim.cmd([[ highlight NvimTreeFolderArrowOpen guifg=#3FC5FF ]]) + +nvimtree.setup({ + view = { + width = 45, + relativenumber = true, + }, + renderer = { + indent_markers = { + enable = true, + }, + icons = { + glyphs = { + + folder = { + arrow_closed = "", -- arrow when folder is closed + arrow_open = "", -- arrow when folder is open + } + } + } + }, + -- disable window_picker for + -- explorer to work well with + -- window splits + actions = { + open_file = { + window_picker = { + enable = false, + }, + }, + }, + filters = { + custom = { ".DS_Store" }, + }, + git = { + ignore = false, + } + + }) diff --git a/lua/absolute/after/nvim-treesitter.lua b/lua/absolute/after/nvim-treesitter.lua new file mode 100644 index 0000000..6cb18c8 --- /dev/null +++ b/lua/absolute/after/nvim-treesitter.lua @@ -0,0 +1,22 @@ +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the five listed parsers should always be installed) + ensure_installed = {"rust", "javascript", "typescript", "python", "c", "lua", "vim", "vimdoc", "query" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, + + ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) + -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! + + highlight = { + enable = true, + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +} diff --git a/lua/absolute/after/rose-pine.lua b/lua/absolute/after/rose-pine.lua new file mode 100644 index 0000000..759fcc5 --- /dev/null +++ b/lua/absolute/after/rose-pine.lua @@ -0,0 +1,4 @@ +vim.cmd.colorscheme("rose-pine") +vim.api.nvim_set_hl(0, "Normal", {bg = "none"}) +vim.api.nvim_set_hl(0, "NormalFloat", {bg = "none"}) + diff --git a/lua/absolute/after/telescope.lua b/lua/absolute/after/telescope.lua new file mode 100644 index 0000000..dcbf0cf --- /dev/null +++ b/lua/absolute/after/telescope.lua @@ -0,0 +1,6 @@ +local builtin = require('telescope.builtin') +vim.keymap.set('n', 'pf', builtin.find_files, {}) +vim.keymap.set('n', '', builtin.git_files, {}) +vim.keymap.set('n', 'ps', function() + builtin.grep_string({search = vim.fn.input("Grep > ") }); +end) diff --git a/lua/absolute/after/undotree.lua b/lua/absolute/after/undotree.lua new file mode 100644 index 0000000..b6b9276 --- /dev/null +++ b/lua/absolute/after/undotree.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) diff --git a/lua/absolute/after/vim-fugitive.lua b/lua/absolute/after/vim-fugitive.lua new file mode 100644 index 0000000..73b78b8 --- /dev/null +++ b/lua/absolute/after/vim-fugitive.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "gs", vim.cmd.Git); diff --git a/lua/absolute/core/init.lua b/lua/absolute/core/init.lua new file mode 100644 index 0000000..a483467 --- /dev/null +++ b/lua/absolute/core/init.lua @@ -0,0 +1,33 @@ +vim.opt.guicursor = "" + +vim.opt.nu = true +vim.opt.relativenumber = true + +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true + +vim.opt.smartindent = true + +vim.opt.wrap = false + +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" +vim.opt.undofile = true + +vim.opt.hlsearch = false +vim.opt.incsearch = true + +vim.opt.termguicolors = true + +vim.opt.scrolloff = 8 +vim.opt.signcolumn = "yes" +vim.opt.isfname:append("@-@") + +vim.opt.updatetime = 50 + +vim.opt.colorcolumn = "100" + +vim.g.mapleader = " " diff --git a/lua/absolute/init.lua b/lua/absolute/init.lua new file mode 100644 index 0000000..18e6654 --- /dev/null +++ b/lua/absolute/init.lua @@ -0,0 +1,3 @@ +require("absolute.remap") +require("absolute.core") +require("absolute.lazy") diff --git a/lua/absolute/lazy.lua b/lua/absolute/lazy.lua new file mode 100644 index 0000000..28637ac --- /dev/null +++ b/lua/absolute/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("absolute.plugins") diff --git a/lua/absolute/plugins/copilot.lua b/lua/absolute/plugins/copilot.lua new file mode 100644 index 0000000..a1b775d --- /dev/null +++ b/lua/absolute/plugins/copilot.lua @@ -0,0 +1,3 @@ +return { + "github/copilot.vim" +} diff --git a/lua/absolute/plugins/harpoon.lua b/lua/absolute/plugins/harpoon.lua new file mode 100644 index 0000000..ca7577b --- /dev/null +++ b/lua/absolute/plugins/harpoon.lua @@ -0,0 +1,7 @@ +return { + "theprimeagen/harpoon", + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + require("absolute.after.harpoon") + end +} diff --git a/lua/absolute/plugins/lsp-zero.lua b/lua/absolute/plugins/lsp-zero.lua new file mode 100644 index 0000000..8900e5c --- /dev/null +++ b/lua/absolute/plugins/lsp-zero.lua @@ -0,0 +1,15 @@ +return { + + 'VonHeikemen/lsp-zero.nvim', branch = 'v3.x', + dependencies = { + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + 'neovim/nvim-lspconfig', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/nvim-cmp', + 'L3MON4D3/LuaSnip', + }, + config = function() + require("absolute.after.lsp-zero") + end +} diff --git a/lua/absolute/plugins/nvim-cmp.lua b/lua/absolute/plugins/nvim-cmp.lua new file mode 100644 index 0000000..e689604 --- /dev/null +++ b/lua/absolute/plugins/nvim-cmp.lua @@ -0,0 +1,17 @@ +return { + 'hrsh7th/nvim-cmp', + event = "InsertEnter", + dependencies = { + 'neovim/nvim-lspconfig', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', + "saadparwaiz1/cmp_luasnip", + "onsails/lspkind.nvim", + }, + config = function() + require("absolute.after.nvim-cmp") + + end +} diff --git a/lua/absolute/plugins/nvim-tree.lua b/lua/absolute/plugins/nvim-tree.lua new file mode 100644 index 0000000..df5197e --- /dev/null +++ b/lua/absolute/plugins/nvim-tree.lua @@ -0,0 +1,7 @@ +return { + "nvim-tree/nvim-tree.lua", + dependencies = {"nvim-tree/nvim-web-devicons"}, + config = function() + require("absolute.after.nvim-tree"); + end +} diff --git a/lua/absolute/plugins/nvim-treesitter-playground.lua b/lua/absolute/plugins/nvim-treesitter-playground.lua new file mode 100644 index 0000000..8598bcd --- /dev/null +++ b/lua/absolute/plugins/nvim-treesitter-playground.lua @@ -0,0 +1,6 @@ +return { + "nvim-treesitter/playground", + + + +} diff --git a/lua/absolute/plugins/nvim-treesitter.lua b/lua/absolute/plugins/nvim-treesitter.lua new file mode 100644 index 0000000..ee50c9f --- /dev/null +++ b/lua/absolute/plugins/nvim-treesitter.lua @@ -0,0 +1,7 @@ +return { + "nvim-treesitter/nvim-treesitter", + config = function() + vim.cmd([[:TSUpdate]]) + require("absolute.after.nvim-treesitter") + end +} diff --git a/lua/absolute/plugins/rose-pine.lua b/lua/absolute/plugins/rose-pine.lua new file mode 100644 index 0000000..80c4687 --- /dev/null +++ b/lua/absolute/plugins/rose-pine.lua @@ -0,0 +1,7 @@ + return { + 'rose-pine/neovim', + name = 'rose-pine', + config = function() + require("absolute.after.rose-pine") + end +} diff --git a/lua/absolute/plugins/telescope.lua b/lua/absolute/plugins/telescope.lua new file mode 100644 index 0000000..2f2050f --- /dev/null +++ b/lua/absolute/plugins/telescope.lua @@ -0,0 +1,16 @@ +return { + 'nvim-telescope/telescope.nvim', tag = '0.1.5', + dependencies = { 'nvim-lua/plenary.nvim'}, + requires = { + { + "nvim-telescope/telescope-fzf-native.nvim", + run = "make" + }, + { + "nvim-telescope/telescope-dap.nvim" + } + }, + config = function() + require("absolute.after.telescope") + end + } diff --git a/lua/absolute/plugins/undotree.lua b/lua/absolute/plugins/undotree.lua new file mode 100644 index 0000000..ba42d34 --- /dev/null +++ b/lua/absolute/plugins/undotree.lua @@ -0,0 +1,6 @@ +return { + "mbbill/undotree", + config = function() + require("absolute.after.undotree") + end +} diff --git a/lua/absolute/plugins/vim-fugitive.lua b/lua/absolute/plugins/vim-fugitive.lua new file mode 100644 index 0000000..c7e8412 --- /dev/null +++ b/lua/absolute/plugins/vim-fugitive.lua @@ -0,0 +1,7 @@ +return { + "tpope/vim-fugitive", + config = function() + require("absolute.after.vim-fugitive") + end + +} diff --git a/lua/absolute/plugins/vim-tmux-navigator.lua b/lua/absolute/plugins/vim-tmux-navigator.lua new file mode 100644 index 0000000..ad47dd0 --- /dev/null +++ b/lua/absolute/plugins/vim-tmux-navigator.lua @@ -0,0 +1,17 @@ +return { + "christoomey/vim-tmux-navigator", + cmd = { + "TmuxNavigateLeft", + "TmuxNavigateDown", + "TmuxNavigateUp", + "TmuxNavigateRight", + "TmuxNavigatePrevious", + }, + keys = { + { "", "TmuxNavigateLeft" }, + { "", "TmuxNavigateDown" }, + { "", "TmuxNavigateUp" }, + { "", "TmuxNavigateRight" }, + { "", "TmuxNavigatePrevious" }, + }, + } diff --git a/lua/absolute/remap.lua b/lua/absolute/remap.lua new file mode 100644 index 0000000..2965921 --- /dev/null +++ b/lua/absolute/remap.lua @@ -0,0 +1,35 @@ +vim.g.mapleader = " " + +vim.keymap.set("n", "\\", "NvimTreeToggle") -- toggle file explorer + +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") + +vim.keymap.set("n", "J", "mzJ`z") +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "n", "nzzzv") +vim.keymap.set("n", "N", "Nzzzv") + +vim.keymap.set("x", "p", [["_dP]]) + +vim.keymap.set({"n", "v"}, "y", [["+y]]) +vim.keymap.set("n", "Y", [["+Y]]) + +vim.keymap.set({"n", "v"}, "d", [["_d]]) + +vim.keymap.set("i", "", "") + +vim.keymap.set("n", "Q", "") +vim.keymap.set("n", "f", vim.lsp.buf.format) + +vim.keymap.set("n", "", "cnextzz") +vim.keymap.set("n", "", "cprevzz") +vim.keymap.set("n", "k", "lnextzz") +vim.keymap.set("n", "j", "lprevzz") + +vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) + +vim.keymap.set("n", "", function() + vim.cmd("so") +end)