diff --git a/init.lua b/init.lua index 4315e5b..c7c28fd 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,7 @@ require("user.autocommands") require("user.cmp") require("user.cmp_gh_source") require("user.telescope") +require("user.todo") require("user.treesitter") require("user.autopairs") require("user.comment") @@ -27,3 +28,4 @@ require("user.crates") require("user.colorizer") require("user.luasnip") require("user.autosave") +require("user.persistence") diff --git a/lua/user/alpha.lua b/lua/user/alpha.lua index f30e1b7..a4c07b0 100644 --- a/lua/user/alpha.lua +++ b/lua/user/alpha.lua @@ -4,30 +4,39 @@ if not status_ok then end local dashboard = require("alpha.themes.dashboard") -dashboard.section.header.val = { - [[ ___ ]], - [[ /\_ \ __ ]], - [[ ____ ___\//\ \ ___ __ __ /\_\ ___ ___ ]], - [[ /',__\ / __`\\ \ \ / __`\/\ \/\ \\/\ \ /' __` __`\ ]], - [[/\__, `\/\ \L\ \\_\ \_/\ \L\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], - [[\/\____/\ \____//\____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], - [[ \/___/ \/___/ \/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], -} +local function header() + return { + [[ ___ ]], + [[ /\_ \ __ ]], + [[ ____ ___\//\ \ ___ __ __ /\_\ ___ ___ ]], + [[ /',__\ / __`\\ \ \ / __`\/\ \/\ \\/\ \ /' __` __`\ ]], + [[/\__, `\/\ \L\ \\_\ \_/\ \L\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], + [[\/\____/\ \____//\____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], + [[ \/___/ \/___/ \/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], + } +end -dashboard.section.buttons.val = { - dashboard.button("f", " " .. " Find file", ":Telescope find_files "), - dashboard.button("e", " " .. " New file", ":ene startinsert "), - dashboard.button("p", " " .. " Find project", ":lua require('telescope').extensions.projects.projects()"), - dashboard.button("r", " " .. " Recent files", ":Telescope oldfiles "), - dashboard.button("t", " " .. " Find text", ":Telescope live_grep "), - dashboard.button("c", " " .. " Config", ":e ~/.config/nvim/init.lua "), - dashboard.button("q", " " .. " Quit", ":qa"), -} local function footer() return "kristofers.xyz" end +dashboard.section.header.val = header() +dashboard.section.buttons.val = { + dashboard.button("f", " " .. " Find file", "Telescope find_files "), + dashboard.button("e", " " .. " New file", "ene startinsert "), + dashboard.button("p", " " .. " Persistence", "lua require('persistence').load()"), + dashboard.button("r", " " .. " Recent files", "Telescope oldfiles "), + dashboard.button("t", " " .. " Find text", "Telescope live_grep "), + dashboard.button( + "P", + " " .. " Find project", + "lua require('telescope').extensions.projects.projects()" + ), + dashboard.button("g", " " .. " Git", "lua _LAZYGIT_TOGGLE()"), + dashboard.button("c", " " .. " Config", "e ~/.config/nvim/init.lua "), + dashboard.button("q", " " .. " Quit", "qa"), +} dashboard.section.footer.val = footer() dashboard.section.footer.opts.hl = "Type" diff --git a/lua/user/autocommands.lua b/lua/user/autocommands.lua index 422aa69..95ca2a4 100644 --- a/lua/user/autocommands.lua +++ b/lua/user/autocommands.lua @@ -48,7 +48,6 @@ vim.api.nvim_create_autocmd({ "TextYankPost" }, { vim.api.nvim_create_autocmd({ "BufWritePre" }, { callback = function() vim.lsp.buf.format() - -- vim.lsp.buf.format({ async = true }) end, }) @@ -59,6 +58,15 @@ vim.api.nvim_create_autocmd({ "InsertEnter" }, { end, }) +-- Disable `expandtab` (don't replace tab with spaces) for lua files +vim.api.nvim_create_autocmd({ "FileType" }, { + pattern = { "lua" }, + callback = function() + vim.opt_local.expandtab = false + end, +}) + +-- Set tab size for the following file types to 2 vim.api.nvim_create_autocmd({ "FileType" }, { pattern = { "vimwiki", "java", "sql" }, callback = function() diff --git a/lua/user/colorizer.lua b/lua/user/colorizer.lua index 225a6ae..a691aaf 100644 --- a/lua/user/colorizer.lua +++ b/lua/user/colorizer.lua @@ -4,16 +4,16 @@ if not status_ok then end colorizer.setup({ - filetypes = { "html", "css", "js" }, + filetypes = { "html", "css", "js", "lua", "yaml", "conf", "toml" }, user_default_options = { - RGB = true, -- #RGB hex codes + RGB = true, -- #RGB hex codes RRGGBB = true, -- #RRGGBB hex codes names = false, -- "Name" codes like Blue or blue RRGGBBAA = true, -- #RRGGBBAA hex codes AARRGGBB = true, -- 0xAARRGGBB hex codes rgb_fn = true, -- CSS rgb() and rgba() functions hsl_fn = true, -- CSS hsl() and hsla() functions - css = true, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB + css = true, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB css_fn = true, -- Enable all CSS *functions*: rgb_fn, hsl_fn -- Available modes for `mode`: foreground, background, virtualtext mode = "background", -- Set the display mode. @@ -29,6 +29,6 @@ colorizer.setup({ }, -- all the sub-options of filetypes apply to buftypes buftypes = {}, - -- html = { names = true }, - -- css = { names = true }, + html = { names = true }, + css = { names = true }, }) diff --git a/lua/user/comment.lua b/lua/user/comment.lua index fdbed43..9744a46 100644 --- a/lua/user/comment.lua +++ b/lua/user/comment.lua @@ -33,8 +33,8 @@ comment.setup({ ---Add comment at the end of line eol = "gcA", }, - ---Enable keybindings - ---NOTE: If given `false` then the plugin won't create any mappings + --- Enable keybindings + --- NOTE: If given `false` then the plugin won't create any mappings mappings = { ---Operator-pending mapping; `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}` basic = true, diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua index de1a8c9..fd68875 100644 --- a/lua/user/keymaps.lua +++ b/lua/user/keymaps.lua @@ -33,8 +33,8 @@ keymap("n", "", ":vertical resize -2", opts) keymap("n", "", ":vertical resize +2", opts) -- -- Navigate buffers --- keymap("n", "", ":bnext", opts) --- keymap("n", "", ":bprevious", opts) +keymap("n", "", ":bnext", opts) +keymap("n", "", ":bprevious", opts) -- Better paste keymap("v", "p", '"_dP', opts) diff --git a/lua/user/luasnip.lua b/lua/user/luasnip.lua index e805ed0..c0b8b16 100644 --- a/lua/user/luasnip.lua +++ b/lua/user/luasnip.lua @@ -89,8 +89,41 @@ end ls.add_snippets(nil, { all = {}, - lua = {}, - rust = {}, + lua = { + s( + "status", + fmt( + [[ + local status_ok, {} = pcall(require, "{}") + if not status_ok then + return + end + ]], + { + i(1), + same(1), + } + ) + ), + }, + rust = { + s( + "modtest", + fmt( + [[ + #[cfg(test)] + mod test {{ + {} + {} + }} + ]], + { + c(1, { t(" use super::*"), t("") }), + i(0), + } + ) + ), + }, python = {}, cpp = { s( diff --git a/lua/user/mason/handlers.lua b/lua/user/mason/handlers.lua index ff446a1..0cbdfe0 100644 --- a/lua/user/mason/handlers.lua +++ b/lua/user/mason/handlers.lua @@ -23,7 +23,7 @@ M.setup = function() end local config = { - virtual_text = false, -- disable virtual text + virtual_text = true, -- virtual text signs = { active = signs, -- show signs }, @@ -55,12 +55,11 @@ local function lsp_keymaps(bufnr) local opts = { noremap = true, silent = true } local keymap = vim.api.nvim_buf_set_keymap keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) - keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + keymap(bufnr, "n", "gd", "lua require('telescope.builtin').lsp_definitions()", opts) keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) keymap(bufnr, "n", "gI", "lua vim.lsp.buf.implementation()", opts) - keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) + keymap(bufnr, "n", "gr", "lua require('telescope.builtin').lsp_references()", opts) keymap(bufnr, "n", "gl", "lua vim.diagnostic.open_float()", opts) - vim.cmd([[command! Format execute "lua vim.lsp.buf.format()"]]) end M.on_attach = function(client, bufnr) diff --git a/lua/user/mason/mason-installer.lua b/lua/user/mason/mason-installer.lua index d261f2a..f16ca47 100644 --- a/lua/user/mason/mason-installer.lua +++ b/lua/user/mason/mason-installer.lua @@ -23,11 +23,11 @@ local servers = { "jsonls", "lua_ls", "phpactor", + "ruff_lsp", "rust_analyzer", "taplo", "texlab", "tsserver", - "yamlls", } mason.setup() diff --git a/lua/user/mason/null-ls.lua b/lua/user/mason/null-ls.lua index 16cf934..6a8b704 100644 --- a/lua/user/mason/null-ls.lua +++ b/lua/user/mason/null-ls.lua @@ -16,7 +16,6 @@ mason_null_ls.setup({ "codespell", "cpplint", "djlint", - "flake8", "gitlint", "html_lint", "isort", @@ -45,7 +44,6 @@ null_ls.setup({ sources = { diagnostics.codespell, diagnostics.cpplint, - diagnostics.flake8, diagnostics.luacheck.with({ extra_args = { "--globals", @@ -54,7 +52,6 @@ null_ls.setup({ }), diagnostics.misspell, diagnostics.mypy, - -- diagnostics.phpcs, formatting.autopep8, formatting.beautysh, formatting.clang_format, diff --git a/lua/user/options.lua b/lua/user/options.lua index 06cfc72..196bb72 100644 --- a/lua/user/options.lua +++ b/lua/user/options.lua @@ -31,7 +31,7 @@ local options = { laststatus = 3, showcmd = false, ruler = false, - numberwidth = 4, -- set number column width to 2 {default 4} + numberwidth = 4, -- set number column width to 4 {default 4} signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time wrap = false, -- display lines as one long line scrolloff = 8, -- is one of my fav diff --git a/lua/user/persistence.lua b/lua/user/persistence.lua new file mode 100644 index 0000000..4bbd303 --- /dev/null +++ b/lua/user/persistence.lua @@ -0,0 +1,10 @@ +local status_ok, persistence = pcall(require, "persistence") +if not status_ok then + return +end + +persistence.setup({ + dir = vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/"), -- directory where session files are saved + options = { "buffers", "curdir", "tabpages", "winsize" }, -- sessionoptions used for saving + pre_save = nil, -- a function to call before saving the session +}) diff --git a/lua/user/plugins.lua b/lua/user/plugins.lua index 63014c5..391324e 100644 --- a/lua/user/plugins.lua +++ b/lua/user/plugins.lua @@ -40,7 +40,6 @@ packer.init({ -- Install your plugins here return packer.startup(function(use) - -- My plugins here use("wbthomason/packer.nvim") -- Have packer manage itself use("nvim-lua/plenary.nvim") -- Useful lua functions used by lots of plugins use("windwp/nvim-autopairs") -- Autopairs, integrates with both cmp and treesitter @@ -56,12 +55,19 @@ return packer.startup(function(use) use("lewis6991/impatient.nvim") use("lukas-reineke/indent-blankline.nvim") use("goolord/alpha-nvim") - use("folke/which-key.nvim") use("andweeb/presence.nvim") use("NvChad/nvim-colorizer.lua") use("alvan/vim-closetag") use("tpope/vim-surround") + use("folke/which-key.nvim") + use("folke/todo-comments.nvim") + use({ + "folke/persistence.nvim", + event = "BufReadPre", -- this will only start session saving when an actual file was opened + module = "persistence", + }) + -- Colorschemes use("lunarvim/darkplus.nvim") use("Mofiqul/dracula.nvim") @@ -107,6 +113,8 @@ return packer.startup(function(use) use({ "nvim-telescope/telescope.nvim", run = ":TSUpdate" }) use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" }) use("nvim-telescope/telescope-media-files.nvim") + use("xiyaowong/telescope-emoji.nvim") + use("nvim-telescope/telescope-frecency.nvim") -- Treesitter use("nvim-treesitter/nvim-treesitter") diff --git a/lua/user/project.lua b/lua/user/project.lua index a4c3cbb..24ce29b 100644 --- a/lua/user/project.lua +++ b/lua/user/project.lua @@ -6,7 +6,7 @@ project.setup({ -- detection_methods = { "lsp", "pattern" }, -- NOTE: lsp detection will get annoying with multiple langs in one project detection_methods = { "pattern" }, -- patterns used to detect root dir, when **"pattern"** is in detection_methods - patterns = { ".git", "Makefile", "package.json", ".venv" }, + patterns = { ".git", "Makefile", "package.json", ".venv", "Cargo.toml", "requirements.txt" }, }) local tele_status_ok, telescope = pcall(require, "telescope") diff --git a/lua/user/telescope.lua b/lua/user/telescope.lua index 100c720..a283109 100644 --- a/lua/user/telescope.lua +++ b/lua/user/telescope.lua @@ -7,12 +7,10 @@ local actions = require("telescope.actions") telescope.setup({ defaults = { - prompt_prefix = " ", selection_caret = " ", path_display = { "smart" }, file_ignore_patterns = { ".git/", "node_modules" }, - mappings = { i = { [""] = actions.cycle_history_next, @@ -22,4 +20,33 @@ telescope.setup({ }, }, }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + }, + media_files = { + -- filetypes whitelist + filetypes = { "png", "webp", "jpg", "jpeg", "mp4", "webm" }, + find_cmd = "rg", + }, + emoji = { + action = function(emoji) + -- argument emoji is a table. + -- {name="", value="", cagegory="", description=""} + + vim.fn.setreg("*", emoji.value) + print([[Press p or "*p to paste this emoji]] .. emoji.value) + + -- insert emoji when picked + -- vim.api.nvim_put({ emoji.value }, 'c', false, true) + end, + }, + }, }) + +telescope.load_extension("fzf") +telescope.load_extension("media_files") +telescope.load_extension("emoji") diff --git a/lua/user/todo.lua b/lua/user/todo.lua new file mode 100644 index 0000000..0350298 --- /dev/null +++ b/lua/user/todo.lua @@ -0,0 +1,69 @@ +local status_ok, todo = pcall(require, "todo-comments") +if not status_ok then + return +end + +todo.setup({ + signs = true, -- show icons in the signs column + sign_priority = 8, -- sign priority + -- keywords recognized as todo comments + keywords = { + FIX = { + icon = " ", -- icon used for the sign, and in search results + color = "error", -- can be a hex color, or a named color (see below) + alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, -- a set of other keywords that all map to this FIX keywords + -- signs = false, -- configure signs for some keywords individually + }, + TODO = { icon = " ", color = "info" }, + HACK = { icon = " ", color = "warning" }, + WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, + PERF = { icon = " ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, + NOTE = { icon = " ", color = "hint", alt = { "INFO" } }, + TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, + }, + gui_style = { + fg = "NONE", -- The gui style to use for the fg highlight group. + bg = "BOLD", -- The gui style to use for the bg highlight group. + }, + merge_keywords = true, -- when true, custom keywords will be merged with the defaults + -- highlighting of the line containing the todo comment + -- * before: highlights before the keyword (typically comment characters) + -- * keyword: highlights of the keyword + -- * after: highlights after the keyword (todo text) + highlight = { + multiline = true, -- enable multine todo comments + multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword + multiline_context = 10, -- extra lines that will be re-evaluated when changing a line + before = "", -- "fg" or "bg" or empty + keyword = "wide", -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg) + after = "fg", -- "fg" or "bg" or empty + pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlighting (vim regex) + comments_only = true, -- uses treesitter to match keywords in comments only + max_line_len = 400, -- ignore lines longer than this + exclude = {}, -- list of file types to exclude highlighting + }, + -- list of named colors where we try to extract the guifg from the + -- list of highlight groups or use the hex color if hl not found as a fallback + colors = { + error = { "DiagnosticError", "ErrorMsg", "#DC2626" }, + warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" }, + info = { "DiagnosticInfo", "#2563EB" }, + hint = { "DiagnosticHint", "#10B981" }, + default = { "Identifier", "#7C3AD" }, + test = { "Identifier", "#FF00FF" }, + }, + search = { + command = "rg", + args = { + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + }, + -- regex that will be used to match keywords. + -- don't replace the (KEYWORDS) placeholder + pattern = [[\b(KEYWORDS):]], -- ripgrep regex + -- pattern = [[\b(KEYWORDS)\b]], -- match without the extra colon. You'll likely get false positives + }, +}) diff --git a/lua/user/whichkey.lua b/lua/user/whichkey.lua index 674e6bc..f049996 100644 --- a/lua/user/whichkey.lua +++ b/lua/user/whichkey.lua @@ -209,6 +209,8 @@ local mappings = { t = { "Telescope live_grep", "Text" }, k = { "Telescope keymaps", "Keymaps" }, C = { "Telescope commands", "Commands" }, + T = { "TodoTelescope", "Todo" }, + m = { "lua require('telescope').extensions.media_files.media_files()", "Media" }, p = { "lua require('telescope.builtin').colorscheme({enable_preview = true})", "Colorscheme with Preview", @@ -259,6 +261,12 @@ local mappings = { T = { "lua require('dap').terminate()", "Terminate" }, l = { "lua require('dap').run_last()", "Run last" }, }, + q = { + name = "Persistence", + s = { "lua require('persistence').load()", "Current directory" }, + l = { "lua require('persistence').load({ last = true })", "Last session" }, + d = { "lua require('persistence').stop()", "Stop" }, + }, } which_key.setup(setup)