diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-03-22 01:25:05 +0100 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-03-22 01:25:05 +0100 |
commit | 535de78034b347a3407aa6ff5287a1b4897172ea (patch) | |
tree | c0787523f460064b5671b703123f7e9f42a59a45 /lua |
First commit!
Diffstat (limited to 'lua')
-rw-r--r-- | lua/user/init.lua | 31 | ||||
-rw-r--r-- | lua/user/lazy.lua | 103 | ||||
-rw-r--r-- | lua/user/map.lua | 78 | ||||
-rw-r--r-- | lua/user/set.lua | 96 |
4 files changed, 308 insertions, 0 deletions
diff --git a/lua/user/init.lua b/lua/user/init.lua new file mode 100644 index 0000000..2b94d59 --- /dev/null +++ b/lua/user/init.lua @@ -0,0 +1,31 @@ +require("user.set") +require("user.map") +require("user.lazy") + +local autocmd = vim.api.nvim_create_autocmd + +local function augroup(name) + return vim.api.nvim_create_augroup("user_" .. name, { clear = true }) +end + +-- [[ Highlight on yank ]] +autocmd("TextYankPost", { + group = augroup("highlight_yank"), + callback = function() + vim.highlight.on_yank() + end, +}) + +-- [[ Auto create parent directory if it doesn't exist ]] +autocmd({ "BufWritePre" }, { + group = augroup("auto_create_dir"), + callback = function(event) + if event.match:match("^%w%w+://") then + return + end + local file = vim.loop.fs_realpath(event.match) or event.match + vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") + end, +}) + +vim.cmd("colorscheme nord") diff --git a/lua/user/lazy.lua b/lua/user/lazy.lua new file mode 100644 index 0000000..8c4fc3d --- /dev/null +++ b/lua/user/lazy.lua @@ -0,0 +1,103 @@ +-- bootstraping +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) + +-- plugins installation and configuration +require("lazy").setup({ + -- lsp setup + { + -- LSP Support + "neovim/nvim-lspconfig", + -- lsp download manager + "williamboman/mason.nvim", + -- automatic lsp setup + "williamboman/mason-lspconfig.nvim", + -- additional formater support + "stevearc/conform.nvim", + -- additional linter support + "mfussenegger/nvim-lint", + -- mason autoinstaller for formatter's and linter's + "WhoIsSethDaniel/mason-tool-installer.nvim", + -- minimal snippet's support + "dcampos/nvim-snippy", + -- basic snippet's + "honza/vim-snippets", + -- cmp for autocompletion + "hrsh7th/nvim-cmp", + -- cmp nvim-lsp plugin + "hrsh7th/cmp-nvim-lsp", + -- cmp snippy support + "dcampos/cmp-snippy", + -- path comletion + "hrsh7th/cmp-path", + -- kind icons + "onsails/lspkind.nvim", + }, + -- Adds git related signs to the gutter, as well as utilities for managing changes + "lewis6991/gitsigns.nvim", + + -- better ntrw + "tpope/vim-vinegar", + + -- integration with tmux keybinds + "christoomey/vim-tmux-navigator", + + -- nord color theme + "shaunsingh/nord.nvim", + + -- auto close brackets + "m4xshen/autoclose.nvim", + + -- Fuzzy Finder (files, lsp, etc) + { + "nvim-telescope/telescope.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope-ui-select.nvim", + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + }, + }, + }, + + { + -- Highlight, edit, and navigate code + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + }, + + { + -- harpoon your way around code + { + "ThePrimeagen/harpoon", + branch = "harpoon2", + requires = { "nvim-lua/plenary.nvim", lazy = true }, + }, + }, + + -- Minimal neovim modules for a lot of things + { "echasnovski/mini.nvim" }, +}, { + performance = { + rtp = { + disabled_plugins = { + "gzip", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin", + }, + }, + }, +}) diff --git a/lua/user/map.lua b/lua/user/map.lua new file mode 100644 index 0000000..7bcee2f --- /dev/null +++ b/lua/user/map.lua @@ -0,0 +1,78 @@ +local map = vim.keymap.set + +-- Leader +vim.g.mapleader = " " +vim.g.maplocalleader = ";" + +-- Move text easilly +map("v", "J", ":m '>+1<CR>gv=gv", { desc = "Move selected text up" }) +map("v", "K", ":m '<-2<CR>gv=gv", { desc = "Move selected text down" }) + +-- better find next and previous +map("n", "n", "nzzzv", { desc = "Keep cursor in middle with search" }) +map("n", "N", "Nzzzv", { desc = "Keep cursor in middle with search" }) + +map("n", "J", "mzJ`z", { desc = "Move up next line with space in between" }) + +-- greatest remap ever +map("x", "<leader>p", [["_dP]], { desc = "Paste while keeping the registry" }) + +-- moving +vim.keymap.set("i", "<C-a>", "<C-o>I", { noremap = true }) +vim.keymap.set("i", "<C-e>", "<C-o>A", { noremap = true }) +vim.keymap.set("i", "<C-k>", "<C-o>D", { noremap = true }) + +-- buffers +vim.keymap.set("n", "gb", "<cmd>buffers<cr>:buffer<Space>", { noremap = true }) +vim.keymap.set("n", "<Leader>q", "<cmd>q!<cr>", { noremap = true }) +vim.keymap.set("n", "<Leader>Q", "<cmd>qa!<cr>", { noremap = true }) +-- close all except focused buffer +vim.keymap.set("n", "<leader>1", "<cmd>%bd|e#<cr>", { noremap = true }) +-- next tab +vim.keymap.set("n", "+", "<cmd>tabe .<cr>", { noremap = true }) + +-- better indenting +map("v", "<", "<gv") +map("v", ">", ">gv") + +-- allow for use of system clipboard fast +map({ "n", "v" }, "<leader>y", [["+y]]) +map("n", "<leader>Y", [["+Y]]) +map({ "n", "v" }, "<leader>P", [["+p]]) + +map({ "n", "v" }, "<leader>d", [["_d]]) + + +-- templates +vim.keymap.set("n", "<LocalLeader>rt", ":-1r " .. vim.fn.stdpath("config") .. "/templates", { noremap = true }) + +-- hide all +local s = {hidden_all = 0} +vim.keymap.set("n", "<C-h>", function () + s.hidden_all = 1 - s.hidden_all + local opt = s.hidden_all == 0 + vim.opt.showmode = opt + vim.opt.ruler = opt + vim.opt.nu = opt + vim.opt.rnu = opt + vim.opt.showcmd = opt + vim.opt.laststatus = opt and 2 or 0 + vim.opt.signcolumn = opt and "yes" or "no" +end, { noremap = true }) + +-- write +vim.keymap.set("n", "<Leader>w", "<cmd>write<cr>", { noremap = true }) +vim.keymap.set("n", "<Leader>W", "<cmd>write!<cr>", { noremap = true }) +vim.keymap.set("n", "<Leader>e", "<cmd>edit<cr>", { noremap = true }) +vim.keymap.set("n", "<LocalLeader>s", function () + vim.cmd.source() + print("sourced.") +end, { noremap = true }) + +-- Lazy +vim.keymap.set("n", "<Leader>P", "<cmd>Lazy<cr>", { noremap = true }) + +-- spelling +vim.keymap.set("n", "<C-s>s", "<cmd>setlocal spell!<cr>", { noremap = true }) +vim.keymap.set("n", "<C-s>g", "z=1<cr><cr>", { noremap = true }) + diff --git a/lua/user/set.lua b/lua/user/set.lua new file mode 100644 index 0000000..2767143 --- /dev/null +++ b/lua/user/set.lua @@ -0,0 +1,96 @@ +local opt = vim.opt + +-- Don't highlight on search +opt.hlsearch = false +opt.incsearch = true + +-- Enable line numbers by default +opt.number = true +opt.relativenumber = true + +-- Tab settings +opt.tabstop = 4 +opt.softtabstop = 4 +opt.shiftwidth = 4 +opt.expandtab = true + +-- Enable smart indenting +opt.smartindent = true + +-- Enable break indent +opt.breakindent = true + +-- History settings +opt.undofile = true +opt.undodir = os.getenv("HOME") .. "/.local/state/nvim" +opt.swapfile = true +opt.swapfile = true + +-- Case-insensitive searching UNLESS \C or capital in search +opt.ignorecase = true +opt.smartcase = true + +-- Keep signcolumn on by default +opt.signcolumn = "yes" + +-- Decrease update time +opt.updatetime = 50 +opt.timeoutlen = 300 + +-- Set completeopt to have a better completion experience +opt.completeopt = "menuone,noselect" + +-- Enable true color support +opt.termguicolors = true + +-- Enable scroll off +opt.scrolloff = 8 + +-- Don't show mode I'm in, already have a nice status line for that +opt.showmode = false + +-- Better split options +opt.splitbelow = true +opt.splitright = true + +-- shared clipboard +opt.clipboard = "unnamed" +-- do not highlight matched bracket +opt.showmatch = false +-- highlight line at cursor +opt.cursorline = true + +-- status line +-- show ruler +opt.ruler = true +-- show command +opt.showcmd = true + +opt.wildmenu = true + +opt.mouse = "" + +opt.backspace = "indent,eol,start" + +opt.laststatus = 2 +opt.history = 200 +opt.encoding = "utf-8" +opt.fileencoding = "utf-8" + +opt.smartindent = true +opt.scrolloff = 8 + +opt.spelllang = "en_us,nl" +opt.formatoptions = "cqrnj" + +-- Get the current working directory, replace the $HOME portion of the path with ~, +-- and extract the last three directories +local cwd = vim.fn.getcwd():gsub(os.getenv('HOME'), '~') +local last_dirs = string.match(cwd, "[^/]+/[^/]+/[^/]+/?$") +if last_dirs then + opt.titlestring = last_dirs .. " -> %t" +else + opt.titlestring = cwd .. " -> %t" +end + +opt.title = true |