diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..dbc863e --- /dev/null +++ b/init.lua @@ -0,0 +1 @@ +require("config") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..16c550d --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,21 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "context.vim": { "branch": "master", "commit": "82eb26de265292808917b82f3eda2725b53d785c" }, + "harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" }, + "lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "4d0e5b49363cac187326998b96aa6a2884e0e89b" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, + "neo-tree.nvim": { "branch": "v3.x", "commit": "a77af2e764c5ed4038d27d1c463fa49cd4794e07" }, + "nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" }, + "nvim": { "branch": "main", "commit": "637d99e638bc6f1efedac582f6ccab08badac0c6" }, + "nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" }, + "nvim-lspconfig": { "branch": "master", "commit": "4cb925e96288a71409a86c84fd97f4434a95453e" }, + "nvim-treesitter": { "branch": "master", "commit": "bb06afa3f1111780932b3c5493ad65473ce85f9d" }, + "nvim-web-devicons": { "branch": "master", "commit": "19d257cf889f79f4022163c3fbb5e08639077bd8" }, + "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, + "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "undotree": { "branch": "master", "commit": "78b5241191852ffa9bb5da5ff2ee033160798c3b" }, + "vim-fugitive": { "branch": "master", "commit": "d4877e54cef67f5af4f950935b1ade19ed6b7370" }, + "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" } +} diff --git a/lazyvim.json b/lazyvim.json new file mode 100644 index 0000000..c8c0d4c --- /dev/null +++ b/lazyvim.json @@ -0,0 +1,9 @@ +{ + "extras": [ + + ], + "news": { + "NEWS.md": "7107" + }, + "version": 6 +} \ No newline at end of file diff --git a/lua/config/init.lua b/lua/config/init.lua new file mode 100644 index 0000000..21eae15 --- /dev/null +++ b/lua/config/init.lua @@ -0,0 +1,3 @@ +require("config.remap") +require("config.set") +require("config.lazy") diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua new file mode 100644 index 0000000..2989a9d --- /dev/null +++ b/lua/config/lazy.lua @@ -0,0 +1,35 @@ +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) + +-- Make sure to setup `mapleader` and `maplocalleader` before +-- loading lazy.nvim so that mappings are correct. +-- This is also a good place to setup other settings (vim.opt) +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" + +-- Setup lazy.nvim +require("lazy").setup({ + spec = { + -- import your plugins + { import = "plugins" }, + }, + -- Configure any other settings here. See the documentation for more details. + -- colorscheme that will be used when installing plugins. + install = { colorscheme = { "catppuccin" } }, + -- automatically check for plugin updates + checker = { enabled = true }, +}) diff --git a/lua/config/remap.lua b/lua/config/remap.lua new file mode 100644 index 0000000..e5ddd97 --- /dev/null +++ b/lua/config/remap.lua @@ -0,0 +1,53 @@ +vim.g.mapleader = " " + +-- Move visually selected lines of text. +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") + +-- Centre screen after motion. +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") + +-- Paste without losing buffer contents. +vim.keymap.set("x", "p", "\"_dP") + +-- Copy to system clipboard. +vim.keymap.set("n", "y", "\"+y") +vim.keymap.set("v", "y", "\"+y") +vim.keymap.set("n", "Y", "\"+Y") + +-- Paste from system clipboard. +vim.keymap.set("n", "p", function() + vim.cmd('normal! "+p') + if vim.fn.search("\\r", "n") > 0 then + vim.cmd('normal! :%s/\r//g') + end +end) +vim.keymap.set("n", "P", function() + vim.cmd('normal! "+P') + if vim.fun.search("\\r", "n" > 0) then + vim.cmd('normal! :%s/\r//g') + end +end) + +-- Avoid accidentally entering Ex mode. +vim.keymap.set("n", "Q", "") + +-- Quickfix/Local list navigation +vim.keymap.set("n", "", "cnextzz") +vim.keymap.set("n", "", "cprevzz") +vim.keymap.set("n", ".", "lnextzz") +vim.keymap.set("n", ",", "lprevzz") + +-- Global replace word +vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) + +-- Set current file to be executable in unix +vim.keymap.set("n", "x", "!chmod +x %", { silent = true }) + +-- Rebind increment and decrement +vim.keymap.set("n", "", "normal! ") +vim.keymap.set("n", "", "normal! ") diff --git a/lua/config/set.lua b/lua/config/set.lua new file mode 100644 index 0000000..220801c --- /dev/null +++ b/lua/config/set.lua @@ -0,0 +1,31 @@ +vim.opt.number = 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 = true + +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 = "80" + +vim.g.mapleader = " " diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..24ea94e --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,11 @@ +return { + -- Install the catppuccin colorscheme + { + "catppuccin/nvim", + lazy = false, + priority = 1000, + config = function() + vim.cmd([[colorscheme catppuccin]]) + end, + }, +} diff --git a/lua/plugins/commentary.lua b/lua/plugins/commentary.lua new file mode 100644 index 0000000..d451e44 --- /dev/null +++ b/lua/plugins/commentary.lua @@ -0,0 +1,6 @@ +return { + "numToStr/Comment.nvim", + config = function() + require("Comment").setup() + end +} diff --git a/lua/plugins/context.lua b/lua/plugins/context.lua new file mode 100644 index 0000000..8bffdac --- /dev/null +++ b/lua/plugins/context.lua @@ -0,0 +1,3 @@ +return { + "wellle/context.vim", +} diff --git a/lua/plugins/fugitive.lua b/lua/plugins/fugitive.lua new file mode 100644 index 0000000..a5b5b04 --- /dev/null +++ b/lua/plugins/fugitive.lua @@ -0,0 +1,6 @@ +return { + "tpope/vim-fugitive", + config = function() + vim.keymap.set("n", "gs", vim.cmd.Git) + end +} diff --git a/lua/plugins/harpoon.lua b/lua/plugins/harpoon.lua new file mode 100644 index 0000000..ce14a1f --- /dev/null +++ b/lua/plugins/harpoon.lua @@ -0,0 +1,21 @@ +return { + "ThePrimeagen/harpoon", + branch = "harpoon2", + dependencies = { "nvim-lua/plenary.nvim" }, + + config = function() + local harpoon = require("harpoon") + + -- REQUIRED + harpoon:setup() + -- REQUIRED + + vim.keymap.set("n", "a", function() harpoon:list():add() end) + vim.keymap.set("n", "", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) + + vim.keymap.set("n", "", function() harpoon:list():select(1) end) + vim.keymap.set("n", "", function() harpoon:list():select(2) end) + vim.keymap.set("n", "", function() harpoon:list():select(3) end) + vim.keymap.set("n", "", function() harpoon:list():select(4) end) + end +} diff --git a/lua/plugins/lspzero.lua b/lua/plugins/lspzero.lua new file mode 100644 index 0000000..2d1a867 --- /dev/null +++ b/lua/plugins/lspzero.lua @@ -0,0 +1,112 @@ +return { + { + 'williamboman/mason.nvim', + lazy = false, + opts = {}, + }, + + -- Autocompletion + { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + config = function() + local cmp = require('cmp') + + cmp.setup({ + sources = { + { name = 'nvim_lsp' }, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + }), + snippet = { + expand = function(args) + vim.snippet.expand(args.body) + end, + }, + }) + end + }, + + -- LSP + { + 'neovim/nvim-lspconfig', + cmd = { 'LspInfo', 'LspInstall', 'LspStart' }, + event = { 'BufReadPre', 'BufNewFile' }, + dependencies = { + { 'hrsh7th/cmp-nvim-lsp' }, + { 'williamboman/mason.nvim' }, + { 'williamboman/mason-lspconfig.nvim' }, + }, + init = function() + -- Reserve a space in the gutter + -- This will avoid an annoying layout shift in the screen + vim.opt.signcolumn = 'yes' + end, + + config = function() + local lsp_defaults = require('lspconfig').util.default_config + + require('mason-lspconfig').setup({ + ensure_installed = { "eslint" }, + handlers = { + -- this first function is the "default handler" + -- it applies to every language server without a "custom handler" + function(server_name) + require('lspconfig')[server_name].setup({}) + end, + } + }) + + -- Add cmp_nvim_lsp capabilities settings to lspconfig + -- This should be executed before you configure any language server + lsp_defaults.capabilities = vim.tbl_deep_extend( + 'force', + lsp_defaults.capabilities, + require('cmp_nvim_lsp').default_capabilities() + ) + + -- LspAttach is where you enable features that only work + -- if there is a language server active in the file + vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function(event) + local opts = { buffer = event.buf } + + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set({ 'n', 'x' }, '', 'lua vim.lsp.buf.format({async = true})', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) + end, + }) + + local cmp = require('cmp') + local cmp_select = { behaviour = cmp.SelectBehavior.Select } + + cmp.setup({ + sources = { + { name = 'nvim_lsp' }, + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.complete(), + }), + }) + end + }, +} diff --git a/lua/plugins/neo-tree.lua b/lua/plugins/neo-tree.lua new file mode 100644 index 0000000..217dd66 --- /dev/null +++ b/lua/plugins/neo-tree.lua @@ -0,0 +1,23 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + -- "3rd/image.nvim", -- Optional image support in preview window: See `# Preview Mode` for more information + }, + config = function() + require("neo-tree").setup({ + window = { + width = 28, + mappings = { + ['e'] = function() vim.api.nvim_exec('Neotree focus filesystem left', true) end, + ['b'] = function() vim.api.nvim_exec('Neotree focus buffers left', true) end, + ['g'] = function() vim.api.nvim_exec('Neotree focus git_status left', true) end, + } + } + }) + vim.keymap.set("n", "jv", "Neotree toggle") + end +} diff --git a/lua/plugins/surround.lua b/lua/plugins/surround.lua new file mode 100644 index 0000000..b5dd6ff --- /dev/null +++ b/lua/plugins/surround.lua @@ -0,0 +1,3 @@ +return { + "tpope/vim-surround" +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..5b9c457 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,13 @@ +return { + 'nvim-telescope/telescope.nvim', tag = '0.1.8', +-- or , branch = '0.1.x', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + local builtin = require('telescope.builtin') + vim.keymap.set('n', 'jf', builtin.find_files, { desc = 'Telescope find files' }) + vim.keymap.set('n', '', builtin.git_files, { desc = 'Git file search'}) + vim.keymap.set('n', 'js', function() + builtin.grep_string({search = vim.fn.input("Grep > ")}) + end) +end +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..a52a7dc --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,34 @@ +return { + -- Install nvim-treesitter + { + "nvim-treesitter/nvim-treesitter", -- The plugin + run = ":TSUpdate", -- Runs :TSUpdate after installation to install parsers + config = function() + require 'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the listed parsers MUST always be installed) + ensure_installed = { "javascript", "typescript", "python", "css", "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline" }, + + -- 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, + + indent = { + enable = true + }, + + highlight = { + enable = true, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- 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, + }, + } + end + } +} diff --git a/lua/plugins/undotree.lua b/lua/plugins/undotree.lua new file mode 100644 index 0000000..1404add --- /dev/null +++ b/lua/plugins/undotree.lua @@ -0,0 +1,6 @@ +return { + "mbbill/undotree", + config = function() + vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) + end +}