commit 366bbcd19d23d7d400bfe0565374535712fdb416 Author: Miroito Date: Fri Apr 14 13:52:05 2023 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e033bc6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lazy-lock.json diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..9d55c74 --- /dev/null +++ b/init.lua @@ -0,0 +1,19 @@ +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) + +vim.g.mapleader = " " +-- keymaps goes first because it sets the leader key +require("keymaps") +require("set") + +require("lazy").setup("plugins") diff --git a/lua/keymaps.lua b/lua/keymaps.lua new file mode 100644 index 0000000..cfcf368 --- /dev/null +++ b/lua/keymaps.lua @@ -0,0 +1,8 @@ +-- CONVENIENCE DEFAULT REMAPS +vim.keymap.set('n', '', 'zz') +vim.keymap.set('n', '', 'zz') +vim.keymap.set({ "n", "v" }, "y", [["+y]]) +vim.keymap.set({ "n", "v" }, "p", [["+p]]) +vim.keymap.set("n", "pv", vim.cmd.Ex) +vim.keymap.set({ "n", "v" }, "d", [["_d]]) +vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) diff --git a/lua/plugins/comment.lua b/lua/plugins/comment.lua new file mode 100644 index 0000000..d614eb9 --- /dev/null +++ b/lua/plugins/comment.lua @@ -0,0 +1,6 @@ +return { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end +} diff --git a/lua/plugins/fugitive.lua b/lua/plugins/fugitive.lua new file mode 100644 index 0000000..e1586a3 --- /dev/null +++ b/lua/plugins/fugitive.lua @@ -0,0 +1,3 @@ +return { + "tpope/vim-fugitive" +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..beec4a5 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,45 @@ +return { + 'lewis6991/gitsigns.nvim', + config = function() + require('gitsigns').setup { + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then return ']c' end + vim.schedule(function() gs.next_hunk() end) + return '' + end, { expr = true }) + + map('n', '[c', function() + if vim.wo.diff then return '[c' end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, { expr = true }) + + -- Actions + map({ 'n', 'v' }, 'hs', ':Gitsigns stage_hunk') + map({ 'n', 'v' }, 'hr', ':Gitsigns reset_hunk') + map('n', 'hS', gs.stage_buffer) + map('n', 'hu', gs.undo_stage_hunk) + map('n', 'hR', gs.reset_buffer) + map('n', 'hp', gs.preview_hunk) + map('n', 'hb', function() gs.blame_line { full = true } end) + map('n', 'tb', gs.toggle_current_line_blame) + map('n', 'hd', gs.diffthis) + map('n', 'hD', function() gs.diffthis('~') end) + map('n', 'td', gs.toggle_deleted) + + -- Text object + map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk') + end + } + end +} diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..4ff7286 --- /dev/null +++ b/lua/plugins/lspconfig.lua @@ -0,0 +1,214 @@ +return { + 'neovim/nvim-lspconfig', + 'hrsh7th/nvim-cmp', -- Autocompletion plugin + 'hrsh7th/cmp-nvim-lsp', -- LSP source for nvim-cmp + 'L3MON4D3/LuaSnip', + { + 'jose-elias-alvarez/null-ls.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + local null_ls = require("null-ls") + + local sources = { + -- python + null_ls.builtins.formatting.black.with({ + extra_args = { "--line-length=79" } + }), + null_ls.builtins.formatting.isort, + null_ls.builtins.diagnostics.flake8, + -- java euh script + null_ls.builtins.formatting.prettier, + null_ls.builtins.code_actions.eslint, + null_ls.builtins.diagnostics.eslint, + -- convienence + null_ls.builtins.code_actions.gitsigns, + -- Docker + null_ls.builtins.diagnostics.hadolint, + -- TailwindCSS + null_ls.builtins.formatting.rustywind.with({ + filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact", "vue", "svelte", + "html", "rust" }, + }), + } + + + local lspconfig = require('lspconfig') + + -- Add additional capabilities supported by nvim-cmp + local capabilities = require("cmp_nvim_lsp").default_capabilities() + + local on_attach = function(_, 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.diagnostic.open_float() 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) + vim.keymap.set("n", "ca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "gr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "rn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "fo", function() vim.lsp.buf.format() end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) + end + + + + lspconfig.rust_analyzer.setup { + capabilities = capabilities, + on_attach = on_attach, + settings = { + ['rust-analyzer'] = { + checkOnSave = { + allFeatures = true, + overrideCommand = { + 'cargo', 'clippy', '--workspace', '--message-format=json', + '--all-targets', '--all-features' + } + } + } + } + } + + lspconfig.lua_ls.setup { + on_attach = on_attach, + capabilities = capabilities, + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + globals = { 'vim' }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + enable = false, + }, + }, + }, + } + + lspconfig.tsserver.setup { + capabilities = capabilities, + on_attach = on_attach, + } + + lspconfig.vuels.setup { + capabilities = capabilities, + on_attach = on_attach, + } + + lspconfig.pyright.setup { + capabilities = capabilities, + on_attach = on_attach, + } + + lspconfig.bashls.setup { + capabilities = capabilities, + on_attach = on_attach, + } + + lspconfig.clangd.setup { + capabilities = capabilities, + on_attach = on_attach, + } + + -- lspconfig.volar.setup { + -- filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' }, + -- capabilities = capabilities, + -- on_attach = on_attach, + -- } + + -- Keep null_ls last so that its diagnostics and code actions come last + null_ls.setup({ sources = sources }) + + -- Global mappings. + vim.keymap.set('n', 'e', vim.diagnostic.open_float) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next) + vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + + -- Use LspAttach autocommand to only map the following keys + -- after the language server attaches to the current buffer + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + -- Buffer local mappings. + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, + }) + + -- nvim-cmp setup + local cmp = require 'cmp' + cmp.setup { + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), -- Up + [''] = cmp.mapping.scroll_docs(4), -- Down + -- C-b (back) C-f (forward) for snippet placeholder navigation. + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { 'i', 's' }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, { + { name = 'buffer' }, + }) + } + + -- Format on save + vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] + end + } +} diff --git a/lua/plugins/markdown.lua b/lua/plugins/markdown.lua new file mode 100644 index 0000000..804723b --- /dev/null +++ b/lua/plugins/markdown.lua @@ -0,0 +1,9 @@ +return { + { + "iamcco/markdown-preview.nvim", + event = "BufRead", + build = function() + vim.fn["mkdp#util#install"]() + end, + }, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..61f6234 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,44 @@ +return { + 'nvim-telescope/telescope.nvim', + tag = '0.1.1', + dependencies = { + 'nvim-lua/plenary.nvim', + 'debugloop/telescope-undo.nvim', + }, + config = function() + -- TELESCOPE + 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, {}) + vim.keymap.set('n', 'fq', builtin.quickfix, {}) + vim.keymap.set('n', 'fr', builtin.lsp_references, {}) + vim.keymap.set('n', 'fw', builtin.lsp_workspace_symbols, {}) + vim.keymap.set('n', 'fd', builtin.diagnostics, {}) + vim.keymap.set('n', 'fc', builtin.git_commits, {}) + + -- TELESCOPE UNDO + require("telescope").setup({ + extensions = { + undo = { + use_delta = true, + use_custom_command = nil, -- setting this implies `use_delta = false`. Accepted format is: { "bash", "-c", "echo '$DIFF' | delta" } + side_by_side = false, + diff_context_lines = vim.o.scrolloff, + entry_format = "state #$ID, $STAT, $TIME", + mappings = { + i = { + [""] = require("telescope-undo.actions").yank_additions, + [""] = require("telescope-undo.actions").yank_deletions, + [""] = require("telescope-undo.actions").restore, + }, + }, + }, + }, + }) + require("telescope").load_extension("undo") + + vim.keymap.set("n", "u", "Telescope undo") + end +} diff --git a/lua/plugins/tokyonight.lua b/lua/plugins/tokyonight.lua new file mode 100644 index 0000000..71f2cf6 --- /dev/null +++ b/lua/plugins/tokyonight.lua @@ -0,0 +1,9 @@ +return { + 'folke/tokyonight.nvim', + lazy = false, -- make sure we load this during startup if it is your main colorscheme + priority = 1000, -- make sure to load this before all the other start plugins + config = function() + -- load the colorscheme here + vim.cmd([[colorscheme tokyonight-night]]) + end, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..35ad1af --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,114 @@ +return { + "nvim-treesitter/nvim-treesitter", + dependencies = { + "nvim-treesitter/nvim-treesitter-context", + "nvim-treesitter/nvim-treesitter-textobjects", + "nvim-treesitter/playground", + }, + build = ":TSUpdate", + config = function() + require("nvim-treesitter.install").update({ with_sync = true }) + + require("nvim-treesitter.configs").setup { + ensure_installed = "all", + highlight = { enable = true, }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@comment.outer", + ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" }, + ["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" }, + ["is"] = { query = "@scope", query_group = "locals", desc = "Select language scope" }, + ['al'] = '@loop.outer', + ['il'] = '@loop.inner', + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + }, + selection_modes = { + ['@parameter.outer'] = 'v', -- charwise + ['@function.outer'] = 'V', -- linewise + ['@class.outer'] = '', -- blockwise + }, + include_surrounding_whitespace = true, + }, + swap = { + enable = true, + swap_next = { + ["a"] = "@parameter.inner", + }, + swap_previous = { + ["A"] = "@parameter.inner", + }, + }, + lsp_interop = { + enable = true, + border = 'none', + floating_preview_opts = {}, + peek_definition_code = { + ["gf"] = "@function.outer", + ["gc"] = "@class.outer", + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]m"] = "@function.outer", + ["]]"] = { query = "@class.outer", desc = "Next class start" }, + -- + -- You can use regex matching (i.e. lua pattern) and/or pass a list in a "query" key to group multiple queires. + ["]o"] = "@loop.*", + -- ["]o"] = { query = { "@loop.inner", "@loop.outer" } } + -- + -- You can pass a query group to use query from `queries//.scm file in your runtime path. + -- Below example nvim-treesitter's `locals.scm` and `folds.scm`. They also provide highlights.scm and indent.scm. + ["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" }, + ["]z"] = { query = "@fold", query_group = "folds", desc = "Next fold" }, + }, + goto_next_end = { + ["]M"] = "@function.outer", + ["]["] = "@class.outer", + }, + goto_previous_start = { + ["[m"] = "@function.outer", + ["[["] = "@class.outer", + }, + goto_previous_end = { + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", + }, + -- Below will go to either the start or the end, whichever is closer. + -- Use if you want more granular movements + -- Make it even more gradual by adding multiple queries and regex. + goto_next = { + ["]i"] = "@conditional.outer", + }, + goto_previous = { + ["[i"] = "@conditional.outer", + } + }, + }, + } + + local ts_repeat_move = require "nvim-treesitter.textobjects.repeatable_move" + + -- Repeat movement with ; and , + -- ensure ; goes forward and , goes backward regardless of the last direction + vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next) + vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous) + + -- vim way: ; goes to the direction you were moving. + -- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move) + -- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite) + + -- Optionally, make builtin f, F, t, T also repeatable with ; and , + vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f) + vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F) + vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t) + vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T) + end, +} diff --git a/lua/set.lua b/lua/set.lua new file mode 100644 index 0000000..7be4a59 --- /dev/null +++ b/lua/set.lua @@ -0,0 +1,17 @@ +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.undodir = os.getenv("HOME") .. "/.vim/undodir" +vim.opt.undofile = true + +vim.opt.smartindent = true + +vim.opt.wrap = false + +vim.opt.hlsearch = false +vim.opt.incsearch = true