From cc48b42dff8a8781780457005c30dc71763f55bd Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sat, 18 Oct 2025 12:30:57 +0545 Subject: [PATCH] feat: add neogen and mdx syntax highlighting plugins --- lua/config/autocmd.lua | 260 ++++++++++++++++++++--------------------- lua/plugins/coding.lua | 22 ++++ lua/plugins/util.lua | 93 ++++++--------- 3 files changed, 188 insertions(+), 187 deletions(-) diff --git a/lua/config/autocmd.lua b/lua/config/autocmd.lua index 06a7833..37a4ec0 100644 --- a/lua/config/autocmd.lua +++ b/lua/config/autocmd.lua @@ -1,187 +1,187 @@ local function augroup(name) - return vim.api.nvim_create_augroup("nvim" .. name, { clear = true }) + return vim.api.nvim_create_augroup('nvim' .. name, { clear = true }) end -- Strip trailing spaces before write -vim.api.nvim_create_autocmd({ "BufWritePre" }, { - group = augroup("strip_space"), - pattern = { "*" }, - callback = function() - vim.cmd([[ %s/\s\+$//e ]]) - end, +vim.api.nvim_create_autocmd({ 'BufWritePre' }, { + group = augroup('strip_space'), + pattern = { '*' }, + callback = function() + vim.cmd([[ %s/\s\+$//e ]]) + end, }) -- Check if we need to reload the file when it changed -vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, { - group = augroup("checktime"), - command = "checktime", +vim.api.nvim_create_autocmd({ 'FocusGained', 'TermClose', 'TermLeave' }, { + group = augroup('checktime'), + command = 'checktime', }) -- Highlight on yank -vim.api.nvim_create_autocmd("TextYankPost", { - group = augroup("highlight_yank"), - callback = function() - vim.highlight.on_yank() - end, +vim.api.nvim_create_autocmd('TextYankPost', { + group = augroup('highlight_yank'), + callback = function() + vim.highlight.on_yank() + end, }) -- resize splits if window got resized -vim.api.nvim_create_autocmd({ "VimResized" }, { - group = augroup("resize_splits"), - callback = function() - vim.cmd("tabdo wincmd =") - end, +vim.api.nvim_create_autocmd({ 'VimResized' }, { + group = augroup('resize_splits'), + callback = function() + vim.cmd('tabdo wincmd =') + end, }) -- go to last loc when opening a buffer -vim.api.nvim_create_autocmd("BufReadPost", { - group = augroup("last_loc"), - callback = function() - local mark = vim.api.nvim_buf_get_mark(0, '"') - local lcount = vim.api.nvim_buf_line_count(0) - if mark[1] > 0 and mark[1] <= lcount then - pcall(vim.api.nvim_win_set_cursor, 0, mark) - end - end, +vim.api.nvim_create_autocmd('BufReadPost', { + group = augroup('last_loc'), + callback = function() + local mark = vim.api.nvim_buf_get_mark(0, '"') + local lcount = vim.api.nvim_buf_line_count(0) + if mark[1] > 0 and mark[1] <= lcount then + pcall(vim.api.nvim_win_set_cursor, 0, mark) + end + end, }) -- close some filetypes with -vim.api.nvim_create_autocmd("FileType", { - group = augroup("close_with_q"), - pattern = { - "Jaq", - "PlenaryTestPopup", - "Avante", - "AvanteInput", - "AvanteSelectedFiles", - "fugitive", - "git", - "help", - "lir", - "lspinfo", - "man", - "netrw", - "notify", - "qf", - "spectre_panel", - "startuptime", - "tsplayground", - }, - callback = function(event) - vim.bo[event.buf].buflisted = false - vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) - end, +vim.api.nvim_create_autocmd('FileType', { + group = augroup('close_with_q'), + pattern = { + 'Jaq', + 'PlenaryTestPopup', + 'Avante', + 'AvanteInput', + 'AvanteSelectedFiles', + 'fugitive', + 'git', + 'help', + 'lir', + 'lspinfo', + 'man', + 'netrw', + 'notify', + 'qf', + 'spectre_panel', + 'startuptime', + 'tsplayground', + }, + callback = function(event) + vim.bo[event.buf].buflisted = false + vim.keymap.set('n', 'q', 'close', { buffer = event.buf, silent = true }) + end, }) -- wrap and check for spell in text filetypes -vim.api.nvim_create_autocmd("FileType", { - group = augroup("wrap_spell"), - pattern = { "gitcommit", "markdown" }, - callback = function() - vim.opt_local.wrap = true - vim.opt_local.spell = true - end, +vim.api.nvim_create_autocmd('FileType', { + group = augroup('wrap_spell'), + pattern = { 'gitcommit', 'markdown' }, + callback = function() + vim.opt_local.wrap = true + vim.opt_local.spell = true + end, }) -- Auto create dir when saving a file, in case some intermediate directory does not exist -vim.api.nvim_create_autocmd({ "BufWritePre" }, { - group = augroup("auto_create_dir"), - callback = function(event) - local file = vim.loop.fs_realpath(event.match) or event.match - vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") - end, +vim.api.nvim_create_autocmd({ 'BufWritePre' }, { + group = augroup('auto_create_dir'), + callback = function(event) + local file = vim.loop.fs_realpath(event.match) or event.match + vim.fn.mkdir(vim.fn.fnamemodify(file, ':p:h'), 'p') + end, }) -- Set arb filetype -vim.api.nvim_create_autocmd({ "BufEnter" }, { - group = augroup("set_file_type"), - pattern = { "*.arb" }, - command = "setfiletype arb", +vim.api.nvim_create_autocmd({ 'BufEnter' }, { + group = augroup('set_file_type'), + pattern = { '*.arb' }, + command = 'setfiletype arb', }) -- Disable format options -vim.api.nvim_create_autocmd("FileType", { - group = augroup("disable_formatoptions"), - pattern = "*", - callback = function() - vim.opt_local.formatoptions:remove({ "c", "r", "o" }) - end, +vim.api.nvim_create_autocmd('FileType', { + group = augroup('disable_formatoptions'), + pattern = '*', + callback = function() + vim.opt_local.formatoptions:remove({ 'c', 'r', 'o' }) + end, }) local function enable_autoformat() - vim.api.nvim_create_autocmd({ "BufWritePre" }, { - group = augroup("autoformat"), - pattern = { "*" }, - callback = function() - vim.lsp.buf.format() - end, - }) + vim.api.nvim_create_autocmd({ 'BufWritePre' }, { + group = augroup('autoformat'), + pattern = { '*' }, + callback = function() + vim.lsp.buf.format() + end, + }) end enable_autoformat() -vim.api.nvim_create_user_command("WriteNoFormat", function() - -- Temporarily disable the autoformat autocmd - vim.api.nvim_del_augroup_by_name("keycodex_autoformat") - vim.cmd("write") - -- Re-enable the autoformat autocmd - enable_autoformat() +vim.api.nvim_create_user_command('WriteNoFormat', function() + -- Temporarily disable the autoformat autocmd + vim.api.nvim_del_augroup_by_name('keycodex_autoformat') + vim.cmd('write') + -- Re-enable the autoformat autocmd + enable_autoformat() end, {}) -- Macro recording notifications -vim.api.nvim_create_autocmd("RecordingEnter", { - callback = function() - vim.notify("Macro recording started", vim.log.levels.INFO, { - title = "Macro", - timeout = 2000, - }) - -- Print to command line for debugging - vim.cmd("echo 'Recording macro...'") - end, +vim.api.nvim_create_autocmd('RecordingEnter', { + callback = function() + vim.notify('Macro recording started', vim.log.levels.INFO, { + title = 'Macro', + timeout = 2000, + }) + -- Print to command line for debugging + vim.cmd("echo 'Recording macro...'") + end, }) -vim.api.nvim_create_autocmd("RecordingLeave", { - callback = function() - vim.notify("Macro recording stopped", vim.log.levels.INFO, { - title = "Macro", - timeout = 2000, - }) - -- Print to command line for debugging - vim.cmd("echo 'Macro recording stopped'") - end, +vim.api.nvim_create_autocmd('RecordingLeave', { + callback = function() + vim.notify('Macro recording stopped', vim.log.levels.INFO, { + title = 'Macro', + timeout = 2000, + }) + -- Print to command line for debugging + vim.cmd("echo 'Macro recording stopped'") + end, }) -- Function to show macro replay notification local function show_macro_replay(count) - local message = count > 1 and string.format("Replaying macro %d times", count) or "Replaying macro" - vim.notify(message, vim.log.levels.INFO, { - title = "Macro", - timeout = 2000, - }) + local message = count > 1 and string.format('Replaying macro %d times', count) or 'Replaying macro' + vim.notify(message, vim.log.levels.INFO, { + title = 'Macro', + timeout = 2000, + }) end -- Function to clear all macros local function clear_all_macros() - -- Clear all registers from a to z - for i = 97, 122 do -- ASCII values for 'a' to 'z' - vim.fn.setreg(string.char(i), "") - end - -- Clear all registers from 0 to 9 - for i = 48, 57 do -- ASCII values for '0' to '9' - vim.fn.setreg(string.char(i), "") - end - vim.notify("All macros cleared", vim.log.levels.INFO, { - title = "Macro", - timeout = 2000, - }) + -- Clear all registers from a to z + for i = 97, 122 do -- ASCII values for 'a' to 'z' + vim.fn.setreg(string.char(i), '') + end + -- Clear all registers from 0 to 9 + for i = 48, 57 do -- ASCII values for '0' to '9' + vim.fn.setreg(string.char(i), '') + end + vim.notify('All macros cleared', vim.log.levels.INFO, { + title = 'Macro', + timeout = 2000, + }) end -- Create keymaps for macro replay with notifications -vim.keymap.set("n", "@", function() - local count = vim.v.count1 - show_macro_replay(count) - return "@" +vim.keymap.set('n', '@', function() + local count = vim.v.count1 + show_macro_replay(count) + return '@' end, { expr = true }) -- Add keybinding to clear all macros -vim.keymap.set("n", "mc", clear_all_macros, { desc = "Clear all macros" }) +vim.keymap.set('n', 'oc', clear_all_macros, { desc = 'Clear all macros' }) diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua index 6cdb5e8..46302e1 100644 --- a/lua/plugins/coding.lua +++ b/lua/plugins/coding.lua @@ -174,4 +174,26 @@ return { }) end, }, + + -- annotation generator + { + 'danymat/neogen', + opts = { + snippet_engine = 'luasnip', + languages = { + python = { + template = { + annotation_convention = 'google_docstrings', + }, + }, + }, + }, + }, + + -- syntax highlight for mdx + { + 'davidmh/mdx.nvim', + config = true, + dependencies = { 'nvim-treesitter/nvim-treesitter' }, + }, } diff --git a/lua/plugins/util.lua b/lua/plugins/util.lua index 4112941..7cc98b9 100644 --- a/lua/plugins/util.lua +++ b/lua/plugins/util.lua @@ -1,42 +1,21 @@ return { - { - "danymat/neogen", - dependencies = { "nvim-treesitter/nvim-treesitter" }, - opts = { - snippet_engine = "luasnip", - languages = { - python = { - template = { - annotation_convention = "google_docstrings", - }, - }, - }, - }, - }, - - { - "davidmh/mdx.nvim", - config = true, - dependencies = { "nvim-treesitter/nvim-treesitter" }, - }, - -- better escape { - "max397574/better-escape.nvim", + 'max397574/better-escape.nvim', config = function() - require("better_escape").setup({ + require('better_escape').setup({ mappings = { -- i for insert, other modes are the first letter too i = { -- map kj to exit insert mode k = { - j = "", + j = '', }, -- map jk and jj to exit insert mode j = { - k = "", - j = "", + k = '', + j = '', }, -- disable jj j = { @@ -50,43 +29,43 @@ return { -- Navigator { - "numToStr/Navigator.nvim", - event = "VeryLazy", + 'numToStr/Navigator.nvim', + event = 'VeryLazy', config = function() - require("Navigator").setup({ - auto_save = "current", + require('Navigator').setup({ + auto_save = 'current', disable_on_zoom = false, - mux = "auto", + mux = 'auto', }) end, }, -- float terminal { - "akinsho/toggleterm.nvim", - cmd = { "ToggleTerm" }, - version = "*", + 'akinsho/toggleterm.nvim', + cmd = { 'ToggleTerm' }, + version = '*', config = function() - require("toggleterm").setup({ + require('toggleterm').setup({ size = 10, open_mapping = [[]], hide_numbers = true, shade_filetypes = {}, shade_terminals = true, - shading_factor = "2", + shading_factor = '2', start_in_insert = true, insert_mappings = true, terminal_mappings = true, persist_size = true, - direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' + direction = 'float', -- 'vertical' | 'horizontal' | 'tab' | 'float' close_on_exit = true, shell = vim.o.shell, float_opts = { - border = "curved", -- 'single', 'double', 'shadow', etc. - winblend = 0, -- Set to 0 for full transparency + border = 'curved', -- 'single', 'double', 'shadow', etc. + winblend = 0, -- Set to 0 for full transparency highlights = { - border = "Normal", - background = "Normal", + border = 'Normal', + background = 'Normal', }, }, }) @@ -95,7 +74,7 @@ return { -- smooth scrolling { - "karb94/neoscroll.nvim", + 'karb94/neoscroll.nvim', opts = {}, }, @@ -107,33 +86,33 @@ return { -- uv { - "benomahony/uv.nvim", - ft = "python", - event = "BufReadPre", + 'benomahony/uv.nvim', + ft = 'python', + event = 'BufReadPre', opts = { picker_integration = true, keymaps = { - prefix = "u", -- Main prefix for uv commands - commands = true, -- Show uv commands menu (x) - run_file = true, -- Run current file (xr) + prefix = 'u', -- Main prefix for uv commands + commands = true, -- Show uv commands menu (x) + run_file = true, -- Run current file (xr) run_selection = true, -- Run selected code (xs) - run_function = true, -- Run function (xf) - venv = true, -- Environment management (xe) - init = true, -- Initialize uv project (xi) - add = true, -- Add a package (xa) - remove = true, -- Remove a package (xd) - sync = true, -- Sync packages (xc) - sync_all = true, -- Sync all packages, extras and groups (xC) + run_function = true, -- Run function (xf) + venv = true, -- Environment management (xe) + init = true, -- Initialize uv project (xi) + add = true, -- Add a package (xa) + remove = true, -- Remove a package (xd) + sync = true, -- Sync packages (xc) + sync_all = true, -- Sync all packages, extras and groups (xC) }, }, }, -- wakatime - { "wakatime/vim-wakatime", event = "VimEnter", lazy = false }, + { 'wakatime/vim-wakatime', event = 'VimEnter', lazy = false }, -- workflow { - "m4xshen/hardtime.nvim", + 'm4xshen/hardtime.nvim', lazy = false, opts = {}, },