diff --git a/.gitignore b/.gitignore index cc5457a..d2d1108 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ debug foo.* *.log data +packer_compiled.lua diff --git a/lua/flip/init.lua b/lua/flip/init.lua new file mode 100644 index 0000000..a3d288f --- /dev/null +++ b/lua/flip/init.lua @@ -0,0 +1,3 @@ +require("flip.remap") +require("flip.set") +require("flip.lazy") diff --git a/lua/flip/lazy.lua b/lua/flip/lazy.lua new file mode 100644 index 0000000..6f520e4 --- /dev/null +++ b/lua/flip/lazy.lua @@ -0,0 +1,27 @@ +-- 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) + + +-- Setup lazy.nvim +require("lazy").setup({ + spec = "plugins", + change_detection = { notify = false }, + -- Configure any other settings here. See documentation for details + install = { colorscheme = { "habamax" } }, + -- automatically check for plugin updates + checker = { enabled = true }, +}) diff --git a/lua/flip/remap.lua b/lua/flip/remap.lua new file mode 100644 index 0000000..ba36398 --- /dev/null +++ b/lua/flip/remap.lua @@ -0,0 +1,71 @@ +-- Leader is space now +vim.g.mapleader = " " +-- Project View instead of :Ex +vim.keymap.set("n", "pv", vim.cmd.Ex) + +-- Easily move up and down +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") + +-- Slide lines below into the current one +vim.keymap.set("n", "J", "mzJ`z") + +--- LSP settings --- +-- Show hover text of symbol +vim.keymap.set("n", "K", vim.lsp.buf.hover) + +-- Go to definition of symbol +vim.keymap.set("n", "gd", vim.lsp.buf.definition) + +-- Go to declaration of symbol +vim.keymap.set("n", "gD", vim.lsp.buf.declaration) + +-- List all implementations for symbol in quickfix window +vim.keymap.set("n", "gi", vim.lsp.buf.implementation) + +-- Go to definition of type of symbol +vim.keymap.set("n", "go", vim.lsp.buf.type_definition) + +-- Go to references of symbol +vim.keymap.set("n", "gr", vim.lsp.buf.references) + +-- Select code action at symbol +vim.keymap.set("n", "ca", vim.lsp.buf.code_action) + +-- Auto formatting +vim.keymap.set("n", "f", vim.lsp.buf.format) + +-- Display type signature +vim.keymap.set("n", "gs", vim.lsp.buf.signature_help) + +--- End of LSP setings --- + +-- Greatest remap ever +-- Delete visual selection to null and paste latest clipboard entry +vim.keymap.set("x", "p", [["_dP]]) + +-- Next greatest remap ever : asbjornHaland +-- Copy selection and line respectively to system clipboard +vim.keymap.set({ "n", "v" }, "y", [["+y]]) +vim.keymap.set("n", "Y", [["+Y]]) + +-- Delete to null +vim.keymap.set({ "n", "v" }, "d", [["_d]]) + +-- Make next and previous a bit smoother +vim.keymap.set("n", "n", "nzzzv") +vim.keymap.set("n", "N", "Nzzzv") + +-- Jump to next and previous error +vim.keymap.set("n", "", "cnextzz") +vim.keymap.set("n", "", "cprevzz") + +-- Jump to next and previous item in location list +vim.keymap.set("n", "k", "lnextzz") +vim.keymap.set("n", "j", "lprevzz") + +-- Substitute word under cursor +vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) + +-- Make current file executable +vim.keymap.set("n", "x", "!chmod +x %", { silent = true }) diff --git a/lua/flip/set.lua b/lua/flip/set.lua new file mode 100644 index 0000000..c6cab5e --- /dev/null +++ b/lua/flip/set.lua @@ -0,0 +1,35 @@ +-- Setting line numbers +vim.opt.nu = true +vim.opt.relativenumber = true + +-- Setting tabs correctly +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true + +vim.opt.smartindent = true + +-- Setting backup / undo stuff +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" +vim.opt.undofile = true + +-- Search highlighting +vim.opt.hlsearch = false +vim.opt.incsearch = true + +-- Colouring +vim.opt.termguicolors = true + +-- Scrolling stuff +vim.opt.scrolloff = 20 +vim.opt.signcolumn = "yes" +vim.opt.isfname:append("@-@") + +-- Update time +vim.opt.updatetime = 50 + +vim.opt.colorcolumn = "120" + diff --git a/lua/plugins/colors.lua b/lua/plugins/colors.lua new file mode 100644 index 0000000..3b44a87 --- /dev/null +++ b/lua/plugins/colors.lua @@ -0,0 +1,27 @@ +function ColorMyPencils(color) + color = color or "nightfox" + vim.cmd.colorscheme(color) + + vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) + vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" }) +end + +vim.keymap.set("n", "c", function() ColorMyPencils() end) +vim.opt.termguicolors = true + +return { + "EdenEast/nightfox.nvim", + name = "nightfox", + lazy = false, + options = { + colorblind = { + enable = true, + severity = { + protan = 1, + }, + }, + }, + config = function() + ColorMyPencils() + end +} diff --git a/lua/plugins/harpoon.lua b/lua/plugins/harpoon.lua new file mode 100644 index 0000000..0ec521e --- /dev/null +++ b/lua/plugins/harpoon.lua @@ -0,0 +1,15 @@ +return { + "theprimeagen/harpoon", + + config = function() + 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", "1", function() ui.nav_file(1) end) + vim.keymap.set("n", "2", function() ui.nav_file(2) end) + vim.keymap.set("n", "3", function() ui.nav_file(3) end) + vim.keymap.set("n", "4", function() ui.nav_file(4) end) + end +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua new file mode 100644 index 0000000..23a62fe --- /dev/null +++ b/lua/plugins/init.lua @@ -0,0 +1,8 @@ +-- Load prerequisites for plugins here + +return { + { + "nvim-lua/plenary.nvim", + name = "plenary" + } +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..b5b2a11 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,116 @@ +return { + "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "hrsh7th/nvim-cmp", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "j-hui/fidget.nvim", + }, + + config = function() + local cmp = require('cmp') + local cmp_lsp = require("cmp_nvim_lsp") + local capabilities = vim.tbl_deep_extend( + "force", + {}, + vim.lsp.protocol.make_client_capabilities(), + cmp_lsp.default_capabilities()) + + require("fidget").setup({}) + require("mason").setup() + require("mason-lspconfig").setup({ + ensure_installed = { + "clangd", + "lua_ls", + "rust_analyzer", + }, + handlers = { + function(server_name) -- default handler (optional) + require("lspconfig")[server_name].setup { + capabilities = capabilities + } + end, + + zls = function() + local lspconfig = require("lspconfig") + lspconfig.zls.setup({ + root_dir = lspconfig.util.root_pattern(".git", "build.zig", "zls.json"), + settings = { + zls = { + enable_inlay_hints = true, + enable_snippets = true, + warn_style = true, + }, + }, + }) + vim.g.zig_fmt_parse_errors = 0 + vim.g.zig_fmt_autosave = 0 + end, + ["lua_ls"] = function() + local lspconfig = require("lspconfig") + lspconfig.lua_ls.setup { + capabilities = capabilities, + settings = { + Lua = { + runtime = { version = "Lua 5.1" }, + diagnostics = { + globals = { "bit", "vim", "it", "describe", "before_each", "after_each" }, + } + } + } + } + end, + } + }) + + local cmp_select = { behavior = cmp.SelectBehavior.Select } + + cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + 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(), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, -- For luasnip users. + }, { + { name = 'buffer' }, + }) + }) + + local _border = 'rounded' + + vim.diagnostic.config({ + -- update_in_insert = true, + float = { + focusable = false, + style = "minimal", + border = _border, + source = "always", + header = "", + prefix = "", + }, + }) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( + vim.lsp.handlers.hover, { border = _border } + ) + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( + vim.lsp.handlers.signature_help, { border = _border } + ) + require('lspconfig.ui.windows').default_options = { border = _border } + end +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..93b76ac --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,29 @@ +return { + "nvim-telescope/telescope.nvim", + + tag = "0.1.8", + + dependencies = { + "nvim-lua/plenary.nvim" + }, + + config = function() + require('telescope').setup({}) + + local builtin = require('telescope.builtin') + vim.keymap.set('n', 'pf', builtin.find_files, {}) + vim.keymap.set('n', '', builtin.git_files, {}) + vim.keymap.set('n', 'pws', function() + local word = vim.fn.expand("") + builtin.grep_string({ search = word }) + end) + vim.keymap.set('n', 'pWs', function() + local word = vim.fn.expand("") + builtin.grep_string({ search = word }) + end) + vim.keymap.set('n', 'ps', function() + builtin.grep_string({ search = vim.fn.input("Grep > ") }) + end) + vim.keymap.set('n', 'vh', builtin.help_tags, {}) + end +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..cb15dba --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,37 @@ +return { + "nvim-treesitter/nvim-treesitter", + build = function() + require("nvim-treesitter.install").update({ with_sync = true })() + end, + config = function() + require("nvim-treesitter.configs").setup({ + -- List of parsers + ensure_installed = { + "vimdoc", "vim", "lua", "c", "rust", "cpp", "cmake", "latex", "python", "groovy", "bash", "zig", "go", + }, + + sync_install = false, + auto_install = true, + + indent = { + enable = true + }, + + highlight = { + enable = true, + additional_vim_regex_highlighting = { "markdown" }, + }, + }) + + local treesitter_parser_config = require("nvim-treesitter.parsers").get_parser_configs() + treesitter_parser_config.templ = { + install_info = { + url = "https://github.com/vrischmann/tree-sitter-templ.git", + files = { "src/parser.c", "src/scanner.c" }, + branch = "master", + }, + } + + vim.treesitter.language.register("templ", "templ") + end +} diff --git a/lua/plugins/undotree.lua b/lua/plugins/undotree.lua new file mode 100644 index 0000000..5a3f1c5 --- /dev/null +++ b/lua/plugins/undotree.lua @@ -0,0 +1,7 @@ +return { + "mbbill/undotree", + + config = function() + vim.keymap.set("n", "u", vim.cmd.UndoTreeToggle) + end +} diff --git a/lua/plugins/vim-fugitive.lua b/lua/plugins/vim-fugitive.lua new file mode 100644 index 0000000..a5b5b04 --- /dev/null +++ b/lua/plugins/vim-fugitive.lua @@ -0,0 +1,6 @@ +return { + "tpope/vim-fugitive", + config = function() + vim.keymap.set("n", "gs", vim.cmd.Git) + end +}