diff --git a/.dotter/global.toml b/.dotter/global.toml index 1954a53..eeb6499 100644 --- a/.dotter/global.toml +++ b/.dotter/global.toml @@ -50,6 +50,7 @@ depends = ["rust"] [nvim.files] "config/nvim" = "~/.config/nvim" +"config/nvim_unstable" = "~/.config/nvim-unstable" [nvim.files."config/nvim/lua/aleidk/lazy.lua"] target = "~/.config/nvim/lua/aleidk/lazy.lua" type = "template" diff --git a/config/nvim_unstable/init.lua b/config/nvim_unstable/init.lua new file mode 100644 index 0000000..856c8a0 --- /dev/null +++ b/config/nvim_unstable/init.lua @@ -0,0 +1,31 @@ +-- 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) + +require("aleidk.options") + +-- Setup lazy.nvim +require("lazy").setup({ + spec = { + -- import your plugins + { import = "aleidk/plugins" }, + }, + -- Configure any other settings here. See the documentation for more details. + -- colorscheme that will be used when installing plugins. + install = { colorscheme = { "habamax" } }, + -- automatically check for plugin updates + checker = { enabled = true }, +}) diff --git a/config/nvim_unstable/lsp/rust_analyzer.lua b/config/nvim_unstable/lsp/rust_analyzer.lua new file mode 100644 index 0000000..b2b8a12 --- /dev/null +++ b/config/nvim_unstable/lsp/rust_analyzer.lua @@ -0,0 +1,5 @@ +return { + cmd = { "rust-analyzer" }, + filetypes = { 'rust' }, + root_markers = { "cargo.toml" }, +} diff --git a/config/nvim_unstable/lua/aleidk/autocmds.lua b/config/nvim_unstable/lua/aleidk/autocmds.lua new file mode 100644 index 0000000..54e2c9b --- /dev/null +++ b/config/nvim_unstable/lua/aleidk/autocmds.lua @@ -0,0 +1,19 @@ +vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + + if not client then + return + end + + -- Prefer LSP folding if client supports it + if client:supports_method('textDocument/foldingRange') then + local win = vim.api.nvim_get_current_win() + vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()' + end + + if client:supports_method 'textDocument/completion' then + vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = true }) + end + end, +}) diff --git a/config/nvim_unstable/lua/aleidk/options.lua b/config/nvim_unstable/lua/aleidk/options.lua new file mode 100644 index 0000000..ed7f0bf --- /dev/null +++ b/config/nvim_unstable/lua/aleidk/options.lua @@ -0,0 +1,161 @@ +-- [[ Setting options ]] +-- See `:help vim.o` + +-- Set as the leader key +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +vim.o.diffopt = "vertical,closeoff,filler" + +local opt = vim.opt + +vim.schedule(function() + vim.opt.clipboard = 'unnamedplus' +end) + +vim.o.winborder = 'rounded' +opt.breakindent = true -- Every wrapped line will continue visually indented +opt.autowrite = true -- Enable auto write +-- opt.completeopt = "menu,menuone,noselect" +vim.o.completeopt = 'noselect,menu,menuone,noinsert,popup' +opt.conceallevel = 2 -- Hide * markup for bold and italic +opt.confirm = true -- Confirm to save changes before exiting modified buffer +opt.cursorline = true -- Enable highlighting of the current line +opt.expandtab = true -- Use spaces instead of tabs +opt.formatoptions = "jcroqlnt" -- tcqj +opt.grepformat = "%f:%l:%c:%m" +opt.grepprg = "rg --vimgrep" +opt.ignorecase = true -- Ignore case +opt.inccommand = "nosplit" -- preview incremental substitute +opt.laststatus = 0 +vim.opt.list = true -- Sets how neovim will display certain whitespace characters in the editor. +vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } +opt.mouse = "a" -- Enable mouse mode +opt.number = true -- Print line number +opt.pumblend = 10 -- Popup blend +opt.pumheight = 10 -- Maximum number of entries in a popup +opt.relativenumber = true -- Relative line numbers +opt.scrolloff = 15 -- Lines of context +opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" } +opt.shiftround = true -- Round indent +opt.shiftwidth = 2 -- Size of an indent +-- opt.shortmess:append({ W = true, I = true, c = true }) -- INFO: this control the format of some messages +opt.showmode = false -- Don't show mode since we have a statusline +opt.sidescrolloff = 8 -- Columns of context +opt.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift the text each time +opt.smartcase = true -- Don't ignore case with capitals +opt.smartindent = true -- Insert indents automatically +opt.spelllang = { "en" } +opt.splitbelow = true -- Put new windows below current +opt.splitright = true -- Put new windows right of current +opt.tabstop = 2 -- Number of spaces tabs count for +opt.termguicolors = true -- True color support +opt.timeoutlen = 300 +opt.undofile = true +opt.undolevels = 10000 +opt.updatetime = 200 -- Save swap file and trigger CursorHold +opt.wildmode = "longest,list:full" -- Command-line completion mode +opt.winminwidth = 5 -- Minimum window width +opt.wrap = false -- Disable line wrap +vim.opt.inccommand = 'split' -- Preview substitutions live, as you type! + +vim.o.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions" + +-- Nice and simple folding: +vim.o.foldenable = true +vim.o.foldlevel = 99 +vim.o.foldmethod = "expr" +vim.o.foldexpr = "v:lua.vim.treesitter.foldexpr()" +vim.opt.fillchars:append({ fold = " " }) + +local fn = vim.fn + +-- Quickfix customization +function _G.qftf(info) + local items + local ret = {} + -- The name of item in list is based on the directory of quickfix window. + -- Change the directory for quickfix window make the name of item shorter. + -- It's a good opportunity to change current directory in quickfixtextfunc :) + -- + -- local alterBufnr = fn.bufname('#') -- alternative buffer is the buffer before enter qf window + -- local root = getRootByAlterBufnr(alterBufnr) + -- vim.cmd(('noa lcd %s'):format(fn.fnameescape(root))) + -- + if info.quickfix == 1 then + items = fn.getqflist({ id = info.id, items = 0 }).items + else + items = fn.getloclist(info.winid, { id = info.id, items = 0 }).items + end + local limit = 31 + local fnameFmt1, fnameFmt2 = "%-" .. limit .. "s", "…%." .. (limit - 1) .. "s" + local validFmt = "%s │%5d:%-3d│%s %s" + for i = info.start_idx, info.end_idx do + local e = items[i] + local fname = "" + local str + if e.valid == 1 then + if e.bufnr > 0 then + fname = fn.bufname(e.bufnr) + if fname == "" then + fname = "[No Name]" + else + fname = fname:gsub("^" .. vim.env.HOME, "~") + end + -- char in fname may occur more than 1 width, ignore this issue in order to keep performance + if #fname <= limit then + fname = fnameFmt1:format(fname) + else + fname = fnameFmt2:format(fname:sub(1 - limit)) + end + end + local lnum = e.lnum > 99999 and -1 or e.lnum + local col = e.col > 999 and -1 or e.col + local qtype = e.type == "" and "" or " " .. e.type:sub(1, 1):upper() + str = validFmt:format(fname, lnum, col, qtype, e.text) + else + str = e.text + end + table.insert(ret, str) + end + return ret +end + +-- TODO: how to customize? +vim.o.qftf = "{info -> v:lua._G.qftf(info)}" + +vim.filetype.add({ + -- Detect and assign filetype based on the extension of the filename + extension = { + mdx = "mdx", + log = "log", + conf = "conf", + env = "dotenv", + }, + -- Detect and apply filetypes based on the entire filename + filename = { + [".env"] = "dotenv", + ["env"] = "dotenv", + ["tsconfig.json"] = "jsonc", + }, + -- Detect and apply filetypes based on certain patterns of the filenames + pattern = { + -- INFO: Match filenames like - ".env.example", ".env.local" and so on + ["%.env%.[%w_.-]+"] = "dotenv", + [".*%.blade%.php"] = "blade", + [".*%.hurl.*"] = "hurl", + [".*/hypr/.*%.conf"] = "hyprlang", + }, +}) + +-- ╭─────────────────────────────────────────────────────────╮ +-- │ LSP │ +-- ╰─────────────────────────────────────────────────────────╯ + +vim.lsp.enable({ + "rust_analyzer" +}) + +vim.diagnostic.config({ + virtual_lines = { current_line = true } +}) diff --git a/config/nvim_unstable/lua/aleidk/plugins/colorscheme.lua b/config/nvim_unstable/lua/aleidk/plugins/colorscheme.lua new file mode 100644 index 0000000..af5c7fc --- /dev/null +++ b/config/nvim_unstable/lua/aleidk/plugins/colorscheme.lua @@ -0,0 +1,57 @@ +return { -- Change colors.none if not using a transparent background + "catppuccin/nvim", + name = "catppuccin", + priority = 1000, + config = function() + local utils = require("catppuccin.utils.colors") + + local opts = { + flavour = "macchiato", + transparent_background = true, + integrations = { + aerial = true, + blink_cmp = true, + cmp = true, + gitsigns = true, + indent_blankline = { enabled = true, scope_color = "text", }, + lsp_trouble = true, + mason = true, + noice = true, + notify = true, + }, + custom_highlights = function(colors) + return { + -- Fix colors for cmp + Pmenu = { bg = colors.none, blend = 0 }, + FloatBorder = { bg = colors.none }, + CmpItemMenu = { fg = colors.text, bg = colors.none }, + -- dadbod-ui + NotificationInfo = { bg = colors.none, fg = colors.text }, + NotificationWarning = { bg = colors.none, fg = colors.yellow }, + NotificationError = { bg = colors.none, fg = colors.red }, + + -- for word diff in previews + GitSignsAddInline = { + fg = colors.teal, + bg = utils.darken(colors.teal, 0.4), + style = { "bold" }, + }, + GitSignsDeleteInline = { + fg = colors.red, + bg = utils.darken(colors.red, 0.4), + style = { "bold" }, + }, + GitSignsChangeInline = { + fg = colors.mauve, + bg = utils.darken(colors.mauve, 0.4), + style = { "bold" }, + }, + GitSignsDeleteVirtLn = { bg = colors.none, fg = colors.red }, + } + end, + } + + require("catppuccin").setup(opts) + vim.cmd.colorscheme("catppuccin-macchiato") + end, +} diff --git a/config/nvim_unstable/lua/aleidk/plugins/init.lua b/config/nvim_unstable/lua/aleidk/plugins/init.lua new file mode 100644 index 0000000..546a909 --- /dev/null +++ b/config/nvim_unstable/lua/aleidk/plugins/init.lua @@ -0,0 +1,6 @@ +return { + 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically + + + +} diff --git a/config/nvim_unstable/lua/aleidk/plugins/treesitter.lua b/config/nvim_unstable/lua/aleidk/plugins/treesitter.lua new file mode 100644 index 0000000..e281176 --- /dev/null +++ b/config/nvim_unstable/lua/aleidk/plugins/treesitter.lua @@ -0,0 +1,84 @@ +return { + -- Highlight, edit, and navigate code + "nvim-treesitter/nvim-treesitter", + event = { "BufReadPost", "BufNewFile", "BufWritePre", "VeryLazy" }, + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + "JoosepAlviste/nvim-ts-context-commentstring", + "nvim-treesitter/nvim-treesitter-context", + { "windwp/nvim-ts-autotag", opts = {} }, + }, + build = ":TSUpdate", + config = function() + ---@diagnostic disable-next-line: missing-fields + require("nvim-treesitter.configs").setup({ + -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) + auto_install = true, + highlight = { enable = true }, + indent = { enable = true }, + incremental_selection = { + enable = true, + }, + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["aa"] = "@parameter.outer", + ["ia"] = "@parameter.inner", + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_previous = { -- current or last start of object + ["[["] = { query = "@local.scope", query_group = "locals", desc = "Next scope" }, + ["[f"] = "@function.outer", + ["[c"] = "@class.outer", + }, + goto_next = { -- next object end + ["]]"] = { query = "@local.scope", query_group = "locals", desc = "Next scope" }, + ["]f"] = "@function.outer", -- current function end + ["]c"] = "@class.outer", + }, + }, + swap = { + enable = true, + swap_next = { + ["ln"] = "@parameter.inner", + }, + swap_previous = { + ["lN"] = "@parameter.inner", + }, + }, + }, + -- autotag = { enable = true }, + }) + + require('ts_context_commentstring').setup { + enable_autocmd = false, + } + + 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) + + -- Optionally, make builtin f, F, t, T also repeatable with ; and , + vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T_expr, { expr = true }) + + vim.keymap.set("n", "[u", function() + require("treesitter-context").go_to_context() + end, { silent = true, noremap = true, desc = "Go up when context is out of view" }) + end, +} diff --git a/config/zsh/aliases/nvim.zsh b/config/zsh/aliases/nvim.zsh index 5259ff9..4dc86ec 100644 --- a/config/zsh/aliases/nvim.zsh +++ b/config/zsh/aliases/nvim.zsh @@ -1,5 +1,6 @@ alias \ vi='nvim' \ + vi-unstable='NVIM_APPNAME=nvim-unstable nvim' \ vi-astro='NVIM_APPNAME=Distro-AstroNvim nvim' \ vi-lazy='NVIM_APPNAME=LazyVim nvim'