diff options
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/10_options.lua | 53 | ||||
| -rw-r--r-- | plugin/11_keymaps.lua | 58 | ||||
| -rw-r--r-- | plugin/12_autocommands.lua | 135 | ||||
| -rw-r--r-- | plugin/14_commands.lua | 44 | ||||
| -rw-r--r-- | plugin/20_treesitter.lua | 33 | ||||
| -rw-r--r-- | plugin/99_rest.lua | 22 | ||||
| -rw-r--r-- | plugin/plugins/alacritty.lua | 4 | ||||
| -rw-r--r-- | plugin/plugins/conform.lua | 20 | ||||
| -rw-r--r-- | plugin/plugins/mini.lua | 37 | ||||
| -rw-r--r-- | plugin/plugins/oil.lua | 76 | ||||
| -rw-r--r-- | plugin/plugins/quicker.lua | 14 | ||||
| -rw-r--r-- | plugin/plugins/rendermark.lua | 11 | ||||
| -rw-r--r-- | plugin/plugins/scratch.vim | 15 | ||||
| -rw-r--r-- | plugin/plugins/vimtex.lua | 21 |
14 files changed, 543 insertions, 0 deletions
diff --git a/plugin/10_options.lua b/plugin/10_options.lua new file mode 100644 index 0000000..ce3b235 --- /dev/null +++ b/plugin/10_options.lua @@ -0,0 +1,53 @@ +vim.o.title = true +vim.opt.fillchars = { msgsep ="‾", vert="┋" } + +vim.o.autoindent = true +vim.o.expandtab = true +vim.o.shiftwidth = 4 +vim.o.tabstop = 4 +vim.o.cinoptions = "l1,:0,g0,E-s,N-s,t0,(s,J1,j1" +vim.o.virtualedit = "block" + +vim.o.splitright = true +vim.o.splitbelow = true + +vim.o.linebreak = true +vim.o.wrap = true +vim.o.smoothscroll = true + +vim.o.swapfile = false +vim.o.undofile = true +vim.o.shada = "!,'100,<50,s10,:1000,/100,@100,h,r/tmp/,rterm:,rhealth:" + +vim.o.foldlevelstart = 99 +vim.o.foldtext = "" + +vim.o.ignorecase = true +vim.o.smartcase = true +vim.o.incsearch = true +vim.o.inccommand = "split" + +vim.o.completeopt = "menu,menuone,noselect,fuzzy" +vim.o.pumheight = 10 +vim.o.pummaxwidth = 50 +vim.o.wildmode = "longest:full,full" +vim.o.wildoptions = "pum,fuzzy" +vim.opt.wildignore:append({ "*.pyc", "__pycache__", "*~", "#*#", "*.o" }) + +vim.o.spelllang = "en_us,en-academic" +vim.o.spelloptions = "camel" +vim.opt.complete:append("kspell") + +vim.o.signcolumn = "no" + +vim.o.number = true +vim.o.cursorline = true + +vim.g.tex_flavor = "latex" +vim.g.tex_no_error = 1 +vim.g.tex_comment_nospell = 1 +vim.opt.tags:append({ "tags;~", ".tags;~" }) + +vim.o.laststatus = 1 +vim.o.statusline = "%<%f %h%w%m%r %=%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}%{% &busy > 0 ? '◐ ' : '' %}%{% luaeval('(package.loaded[''vim.diagnostic''] and #vim.diagnostic.count() ~= 0 and vim.diagnostic.status() .. '' '') or '''' ') %}%{% v:lua.require'mo.statusline'.lsp_status() %}%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}" + diff --git a/plugin/11_keymaps.lua b/plugin/11_keymaps.lua new file mode 100644 index 0000000..9dcd4f4 --- /dev/null +++ b/plugin/11_keymaps.lua @@ -0,0 +1,58 @@ +local map = function(mode, lhs, rhs, desc) vim.keymap.set(mode, lhs, rhs, { desc = desc }) end +local nmap = function(lhs, rhs, desc) map("n", lhs, rhs, desc) end +local mapleader = function(mode, suffix, rhs, desc) map(mode, "<Leader>" .. suffix, rhs, desc) end +local nmapleader = function(suffix, rhs, desc) mapleader("n", suffix, rhs, desc) end + +map({ "n", "x" }, "gy", '"+y', "copy selection to clipboard") +nmap("gY", '"+Y', "copy to clipboard till end of line") + +nmap("-", "<Cmd>Oil<CR>", "Explore") + +nmap("<C-J>", "<C-w>w", "switch to next window") +nmap("<C-K>", "<C-w>W", "switch to prev window") + +nmap("<C-L>", [[<Cmd>nohlsearch<Bar>diffupdate<CR>]], "nohlsearch and diffupdate") +nmap("<C-S-L>", [[<Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>]], "default neovim <C-L>") + +nmapleader("cd", "<Cmd>lcd %:h<CR>", "lcd to the directory of current file") + +vim.keymap.set({ "n", "x" }, "j", [[v:count == 0 ? 'gj' : 'j']], { expr = true, buffer = 0 }) +vim.keymap.set({ "n", "x" }, "k", [[v:count == 0 ? 'gk' : 'k']], { expr = true, buffer = 0 }) + +nmap("gK", "K", "use the keywordprg instead of hover") + +map('t', '<C-[>', [[<C-\><C-N>]], "go to normal mode from terminal mode") +map('t', '<Esc>', '<Esc>', "map <Esc> to literal ESC in terminal mode") + +-- lua exec +nmapleader("x", function() + local line = "lua " .. vim.api.nvim_get_current_line() + vim.api.nvim_command(line) + vim.api.nvim_input("<Down>") +end, "execute lua line and go to next line") +mapleader("x", "x", ":lua<CR>") +nmap("<Leader><Leader>x", "<Cmd>luafile %<CR>") + +-- lsp and format +nmapleader("e", "<Cmd>lua vim.diagnostic.open_float()<CR>") +nmap("gd", "<Cmd>lua vim.lsp.buf.definition()<CR>") +nmap("<C-f>", "<Cmd>lua require'conform'.format{async=true}<CR>") + +-- fzf +nmap("<C-p>", "<Cmd>FzfLua files<CR>", "fzf: find files") +nmap("<C-t>", "<Cmd>FzfLua resume<CR>", "fzf: resume") +nmap("<C-\\>", "<Cmd>FzfLua buffers<CR>", "fzf: buffers") +nmap("<C-/>", "<Cmd>FzfLua oldfiles<CR>", "fzf: oldfiles") + +nmapleader("fg", "<Cmd>FzfLua live_grep_native<CR>", "fzf: grep") +nmapleader("fc", '<Cmd>FzfLua files prompt="Nvim Config>\\ " cwd=~/.config/nvim<CR>', "fzf: search config") +nmapleader("fp", '<Cmd>lua FzfLua.files({cwd=vim.fn.stdpath("data").."/site/pack/core/opt/"})<CR>', "fzf: search plugins") +nmapleader("fh", "<Cmd>FzfLua helptags<CR>", "fzf: help tags") +nmapleader("fk", "<Cmd>FzfLua keymaps<CR>", "fzf: keymaps") +map("n", "z=", "<Cmd>FzfLua spell_suggest<CR>", "fzf: suggest spelling") + +-- git +nmapleader("gs", "<Cmd>Git<CR>", "git status") + +-- qf +nmapleader("q", function() require("quicker").toggle() end, "Toggle quickfix list") diff --git a/plugin/12_autocommands.lua b/plugin/12_autocommands.lua new file mode 100644 index 0000000..829ed97 --- /dev/null +++ b/plugin/12_autocommands.lua @@ -0,0 +1,135 @@ +local au = vim.api.nvim_create_autocmd +local group = vim.api.nvim_create_augroup("my_events", {}) + +au("TextYankPost", { + group = group, + callback = function() vim.hl.on_yank() end, +}) + +au("TermOpen", { + group = group, + command = "setl stc= nonumber | startinsert!", +}) + +au("BufWritePre", { + group = group, + callback = function() + local view = vim.fn.winsaveview() + vim.cmd([[silent! keepjumps keeppatterns %s/\s\+$//e]]) + vim.fn.winrestview(view) + end, + desc = "remove tail space", +}) + +au("LspAttach", { + group = group, + command = "setl signcolumn=yes | redrawstatus", + desc = "add sign column when LSP is attached and redraw status", +}) + +au("LspDetach", { + group = group, + command = "redrawstatus", + desc = "redraw status when LSP is dettached", +}) + +au("FileType", { + group = group, + pattern = "fugitive,git,help,man,qf,query,scratch", + command = 'execute "nnoremap <buffer> q <Cmd>quit<CR>"', + desc = "Close certain windows by pressing q", +}) + +au("BufWritePost", { + group = group, + desc = "Run shortcuts after updating bookmark files", + pattern = { "bm-dirs", "bm-files" }, + command = "!shortcuts", +}) + +au("User", { + group = group, + pattern = "VimtexEventViewReverse", + desc = "VimTeX: Center view on inverse search", + callback = function() + vim.cmd([[ normal! zMzvzz ]]) + -- If I want to turn on blink again: + -- vim.fn["vimtex#ui#blink"]() + end, +}) + +au("InsertEnter", { + group = group, + desc = "Enable blink.cmp", + once = true, + callback = function() + -- vim.cmd("packadd nvim-cmp") + -- require("mo.cmp") + vim.cmd("packadd blink.cmp") + require("mo.blink").setup() + end, +}) + +local function startuptime() + if vim.g.strive_startup_time ~= nil then return end + vim.g.strive_startup_time = 0 + local usage = vim.uv.getrusage() + if usage then + -- Calculate time in milliseconds (user + system time) + local user_time = (usage.utime.sec * 1000) + (usage.utime.usec / 1000) + local sys_time = (usage.stime.sec * 1000) + (usage.stime.usec / 1000) + vim.g.nvim_startup_time = user_time + sys_time + end +end + +local function show_info() + local plugins = vim.pack.get() + local loaded = vim.iter(plugins) + :map(function(p) return p.active end) + :totable() + local startup_time = vim.g.nvim_startup_time or "0" + local plugin_info_str = string.format( + "load %d/%d plugins in %sms", + #loaded or 0, + #plugins or 0, + startup_time + ) + vim.notify(plugin_info_str, vim.log.levels.INFO) +end + +au("UIEnter", { + group = group, + desc = "Setup Diagnostics and load nohlsearch and undotree package", + once = true, + callback = function() + vim.schedule(function() + -- startuptime() + vim.diagnostic.config({ + virtual_text = { + virt_text_pos = "eol_right_align", + current_line = true, + prefix = function(d, _, _) + -- stylua: ignore start + --- @diagnostic disable-next-line: undefined-field, redundant-return-value + return " ■", "DiagnosticPrefix" .. vim.diagnostic.severity[d.severity] + -- stylua: ignore end + end, + }, + signs = { + text = { "●", "●", "●", "●" }, + numhl = { + "DiagnosticError", + "DiagnosticWarn", + "DiagnosticInfo", + "DiagnosticHint", + }, + }, + severity_sort = true, + }) + + vim.cmd([[packadd nohlsearch]]) + vim.cmd([[packadd nvim.undotree]]) + -- show_info() + end) + end, +}) diff --git a/plugin/14_commands.lua b/plugin/14_commands.lua new file mode 100644 index 0000000..c1f248a --- /dev/null +++ b/plugin/14_commands.lua @@ -0,0 +1,44 @@ +local command = vim.api.nvim_create_user_command + +local complete_plugin_names = function(arg, _, _) + local inactive_plugs_starting_with_arg = vim.tbl_filter( + function(p) return p.active == false and vim.startswith(p.spec.name, arg) end, + vim.pack.get() + ) + return vim.tbl_map(function(p) return p.spec.name end, inactive_plugs_starting_with_arg) +end + +command( + "DiffOrig", + [[ + vert new + setlocal buftype=nofile + read ++edit # + 0d_ + diffthis + wincmd p + diffthis + ]], + { desc = "DiffOrig (see `:h DiffOrig`)" } +) + +command("Pup", function(_) vim.pack.update() end, { desc = "Update packages" }) +command( + "Pdel", + function(opts) vim.pack.del(vim.split(opts.args, " ")) end, + { nargs = "*", complete = complete_plugin_names } +) + +command( + "LspLog", + function() vim.cmd.tabnew(vim.lsp.log.get_filename()) end, + { desc = "Opens the Nvim LSP client log." } +) + +command("Align", function(_) + -- TODO +end, { + nargs = "*", + range = true, + desc = "align selection with respect to a substring", +}) diff --git a/plugin/20_treesitter.lua b/plugin/20_treesitter.lua new file mode 100644 index 0000000..dcc7df2 --- /dev/null +++ b/plugin/20_treesitter.lua @@ -0,0 +1,33 @@ +local disabled = { latex = true, tex = true } +local ft_lang_map = {} + +vim.api.nvim_create_autocmd("FileType", { + group = vim.api.nvim_create_augroup("treesitter_highlight_group", { clear = true }), + callback = function(ev) + local buf = ev.buf + if not vim.api.nvim_buf_is_loaded(buf) then return end + + local ft = vim.bo[buf].filetype + if disabled[ft] then return end + + if ft_lang_map[ft] then + vim.treesitter.language.register(ft_lang_map[ft], ft) + ft_lang_map[ft] = nil + end + + local parser = vim.treesitter.get_parser(buf, nil, { error = false }) + if parser == nil then + disabled[ft] = true + return + end + + if not vim.treesitter.highlighter.active[buf] then + vim.treesitter.highlighter.new(parser) + end + + if vim.treesitter.query.get(ft, "folds") then + vim.wo.foldmethod = "expr" + vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()" + end + end +}) diff --git a/plugin/99_rest.lua b/plugin/99_rest.lua new file mode 100644 index 0000000..481c0ff --- /dev/null +++ b/plugin/99_rest.lua @@ -0,0 +1,22 @@ +vim.schedule( + function() + vim.diagnostic.config({ + float = { header = "" }, + virtual_text = { + current_line = true, + prefix = " ■", + virt_text_pos = "eol_right_align", + }, + signs = { + text = { "●", "●", "●", "●" }, + numhl = { + "DiagnosticError", + "DiagnosticWarn", + "DiagnosticInfo", + "DiagnosticHint", + }, + }, + severity_sort = true, + }) + end +) diff --git a/plugin/plugins/alacritty.lua b/plugin/plugins/alacritty.lua new file mode 100644 index 0000000..f6a323d --- /dev/null +++ b/plugin/plugins/alacritty.lua @@ -0,0 +1,4 @@ +local ok, alacritty = pcall(require, "alacritty") +if not ok then return end + +alacritty.setup() diff --git a/plugin/plugins/conform.lua b/plugin/plugins/conform.lua new file mode 100644 index 0000000..7dfcbb7 --- /dev/null +++ b/plugin/plugins/conform.lua @@ -0,0 +1,20 @@ +---@diagnostic disable: param-type-mismatch + +require("conform").setup({ + formatters_by_ft = { + lua = { "stylua" }, + python = { "ruff_format" }, + rust = { "rustfmt", lsp_format = "fallback" }, + bash = { "shfmt" }, + sh = { "shfmt" }, + tex = { "latexindent" }, + }, + formatters = { + shfmt = { + append_args = { "-i", "4", "-fn" }, + }, + latexindent = { + append_args = { "-m", "-l" }, + }, + }, +}) diff --git a/plugin/plugins/mini.lua b/plugin/plugins/mini.lua new file mode 100644 index 0000000..24027e0 --- /dev/null +++ b/plugin/plugins/mini.lua @@ -0,0 +1,37 @@ +require("mini.notify").setup({ + lsp_progress = { enable = false }, +}) + +local misc = require("mini.misc") +misc.setup_restore_cursor() +misc.setup_termbg_sync() + +vim.schedule(function() + local snippets = require("mini.snippets") + snippets.setup({ + snippets = { + snippets.gen_loader.from_lang(), + }, + }) + local fin_stop = function(args) + if args.data.tabstop_to == "0" then snippets.session.stop() end + end + local au_opts = { pattern = "MiniSnippetsSessionJump", callback = fin_stop } + vim.api.nvim_create_autocmd("User", au_opts) +end) + +vim.schedule(function() + local hipatterns = require("mini.hipatterns") + hipatterns.setup({ + highlighters = { + fixme = { pattern = "FIXME", group = "MiniHipatternsFixme" }, + todo = { pattern = "TODO", group = "MiniHipatternsTodo" }, + note = { pattern = "NOTE", group = "MiniHipatternsNote" }, + hex_color = hipatterns.gen_highlighter.hex_color(), + }, + }) +end) + +vim.schedule(function() + require("mini.icons").setup() +end) diff --git a/plugin/plugins/oil.lua b/plugin/plugins/oil.lua new file mode 100644 index 0000000..edb3c50 --- /dev/null +++ b/plugin/plugins/oil.lua @@ -0,0 +1,76 @@ +require("oil").setup({ + default_file_explorer = true, + columns = { + "permissions", + "size", + -- "mtime", + }, + buf_options = { + buflisted = false, + bufhidden = "hide", + }, + win_options = { + wrap = false, + signcolumn = "no", + cursorcolumn = false, + foldcolumn = "0", + spell = false, + list = false, + conceallevel = 3, + concealcursor = "nvic", + }, + delete_to_trash = false, + skip_confirm_for_simple_edits = false, + prompt_save_on_select_new_entry = true, + cleanup_delay_ms = 2000, + lsp_file_methods = { + enabled = true, + timeout_ms = 1000, + autosave_changes = false, + }, + constrain_cursor = "editable", + watch_for_changes = false, + keymaps = { + ["g?"] = { "actions.show_help", mode = "n" }, + ["<CR>"] = "actions.select", + ["<M-s>"] = { "actions.select", opts = { vertical = true } }, + ["<M-h>"] = { "actions.select", opts = { horizontal = true } }, + ["<M-t>"] = { "actions.select", opts = { tab = true } }, + ["<C-p>"] = false, + ["<C-c>"] = { "actions.close", mode = "n" }, + ["<C-l>"] = "actions.refresh", + ["-"] = { "actions.parent", mode = "n" }, + ["_"] = { "actions.open_cwd", mode = "n" }, + ["`"] = { "actions.cd", mode = "n" }, + ["g~"] = { "actions.cd", opts = { scope = "tab" }, mode = "n" }, + ["gs"] = false, + ["gx"] = "actions.open_external", + ["zh"] = { "actions.toggle_hidden", mode = "n" }, + ["gt"] = "actions.open_terminal", + ["<Leader>Y"] = require("mo.oil-util").copy_to_clipboard, + ["<Leader>y"] = function() require("mo.oil-util").copy_to_clipboard({ full_path = false }) end, + ["<Leader>:"] = { + "actions.open_cmdline", + opts = { shorten_path = true, modify = ":h" }, + }, + ["<Leader>;"] = { + "actions.open_cmdline", + opts = { shorten_path = true }, + }, + }, + use_default_keymaps = false, + view_options = { + show_hidden = false, + is_hidden_file = function(name, _bufnr) + local m = name:match("^%.") + return m ~= nil + end, + is_always_hidden = function(_name, _bufnr) return false end, + natural_order = "fast", + case_insensitive = false, + sort = { + { "type", "asc" }, + { "name", "asc" }, + }, + }, +} --[[@as oil.SetupOpts]]) diff --git a/plugin/plugins/quicker.lua b/plugin/plugins/quicker.lua new file mode 100644 index 0000000..05a537e --- /dev/null +++ b/plugin/plugins/quicker.lua @@ -0,0 +1,14 @@ +require("quicker").setup({ + keys = { + { + ">", + "<cmd>lua require('quicker').expand()<CR>", + desc = "Expand quickfix content", + }, + { + "<", + "<cmd>lua require('quicker').shrink()<CR>", + desc = "Shrink quickfix content", + }, + }, +}) diff --git a/plugin/plugins/rendermark.lua b/plugin/plugins/rendermark.lua new file mode 100644 index 0000000..24e2d16 --- /dev/null +++ b/plugin/plugins/rendermark.lua @@ -0,0 +1,11 @@ +-- vim.api.nvim_create_autocmd("FileType", { +-- pattern = { "markdown" }, +-- once = true, +-- callback = function() +-- vim.cmd([[ packadd render-markdown.nvim ]]) +-- require("render-markdown").setup({ +-- enabled = false, +-- ignore = function(buf) return vim.bo[buf].buftype ~= "nofile" end +-- }) +-- end, +-- }) diff --git a/plugin/plugins/scratch.vim b/plugin/plugins/scratch.vim new file mode 100644 index 0000000..059a21b --- /dev/null +++ b/plugin/plugins/scratch.vim @@ -0,0 +1,15 @@ +if exists('g:loaded_scratch') + finish +endif +let g:loaded_scratch = 1 + +command! -nargs=1 -complete=command Scratch call scratch#open(<q-args>, <q-mods>) +command! -nargs=? Marks <mods> Scratch marks <args> +command! -nargs=0 Messages <mods> Scratch messages +command! -nargs=? Registers <mods> Scratch registers <args> +command! -nargs=? Display <mods> Scratch display <args> +command! -nargs=? -complete=highlight Highlight <mods> Scratch highlight <args> +command! -nargs=0 Jumps <mods> Scratch jumps +command! -nargs=0 Changes <mods> Scratch changes +command! -nargs=0 Digraphs <mods> Scratch digraphs +command! -nargs=0 Scriptnames <mods> Scratch scriptnames diff --git a/plugin/plugins/vimtex.lua b/plugin/plugins/vimtex.lua new file mode 100644 index 0000000..05dfa3a --- /dev/null +++ b/plugin/plugins/vimtex.lua @@ -0,0 +1,21 @@ +vim.g.tex_flavor = "latex" +vim.g.vimtex_compiler_silent = 0 +vim.g.vimtex_complete_bib = { simple = 0 } +vim.g.vimtex_doc_handlers = { "vimtex#doc#handlers#texdoc" } +vim.g.vimtex_format_enabled = 0 +vim.g.vimtex_include_search_enabled = 1 +vim.g.vimtex_indent_on_ampersands = 0 +vim.g.vimtex_quickfix_ignore_filters = { + "Generic hook", + "Package hyperref Warning: Token not allowed in a PDF string", + "destination with the same identifier", + "LaTeX Font Warning:", +} +vim.g.vimtex_quickfix_open_on_warning = 0 +vim.g.vimtex_syntax_conceal_disabled = 1 +vim.g.vimtex_syntax_enabled = 1 +vim.g.vimtex_view_automatic = 0 +vim.g.vimtex_view_forward_search_on_start = 0 +vim.g.vimtex_view_method = "zathura_simple" + +vim.cmd([[packadd vimtex]]) |
