commit f470e78d1c3c51bb7351e3734fd6d285939d6d73 Author: root Date: Sun Aug 10 20:24:22 2025 +0000 init diff --git a/after/ftplugin/cpp.vim b/after/ftplugin/cpp.vim new file mode 100644 index 0000000..564acfe --- /dev/null +++ b/after/ftplugin/cpp.vim @@ -0,0 +1,35 @@ +set commentstring=//\ %s + +" Disable inserting comment leader after hitting o or O or +set formatoptions-=o +set formatoptions-=r + +nnoremap :call compile_run_cpp() + +function! s:compile_run_cpp() abort + let src_path = expand('%:p:~') + let src_noext = expand('%:p:~:r') + let _flag = '-Wall -Wextra -std=c++11 -O2' + + if executable('clang++') + let prog = 'clang++' + elseif executable('g++') + let prog = 'g++' + else + echoerr 'No C++ compiler found on the system!' + endif + call s:create_term_buf('h', 20) + execute printf('term %s %s %s -o %s && %s', prog, _flag, src_path, src_noext, src_noext) + startinsert +endfunction + +function s:create_term_buf(_type, size) abort + set splitbelow + set splitright + if a:_type ==# 'v' + vnew + else + new + endif + execute 'resize ' . a:size +endfunction diff --git a/after/ftplugin/gitconfig.vim b/after/ftplugin/gitconfig.vim new file mode 100644 index 0000000..9c2e80a --- /dev/null +++ b/after/ftplugin/gitconfig.vim @@ -0,0 +1 @@ +set commentstring=#\ %s diff --git a/after/ftplugin/javascript.vim b/after/ftplugin/javascript.vim new file mode 100644 index 0000000..3e27ee8 --- /dev/null +++ b/after/ftplugin/javascript.vim @@ -0,0 +1,3 @@ +" Disable inserting comment leader after hitting o or O or +set formatoptions-=o +set formatoptions-=r diff --git a/after/ftplugin/lua.vim b/after/ftplugin/lua.vim new file mode 100644 index 0000000..a0c7ce0 --- /dev/null +++ b/after/ftplugin/lua.vim @@ -0,0 +1,6 @@ +" Disable inserting comment leader after hitting o or O or +set formatoptions-=o +set formatoptions-=r + +nnoremap :luafile % +nnoremap f silent !stylua % diff --git a/after/ftplugin/markdown.lua b/after/ftplugin/markdown.lua new file mode 100644 index 0000000..f403fb1 --- /dev/null +++ b/after/ftplugin/markdown.lua @@ -0,0 +1,97 @@ +local function add_reference_at_end(label, url, title) + vim.schedule(function() + local bufnr = vim.api.nvim_get_current_buf() + local line_count = vim.api.nvim_buf_line_count(bufnr) + + local ref_def = "[" .. label .. "]: " .. url + if title and title ~= "" then + ref_def = ref_def .. ' "' .. title .. '"' + end + + local buffer_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) + local has_ref_section = false + for _, line in ipairs(buffer_lines) do + if line:match("^%s*[%s]*$") then + has_ref_section = true + break + end + end + + local lines_to_add = {} + if not has_ref_section then + if #lines_to_add == 0 then + table.insert(lines_to_add, "") + end + table.insert(lines_to_add, "") + end + + table.insert(lines_to_add, ref_def) + + vim.api.nvim_buf_set_lines(bufnr, line_count, line_count, false, lines_to_add) + end) +end + +local function get_ref_link_labels() + local labels = {} + local seen = {} + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + + for _, line in ipairs(lines) do + -- %[.-%] matches [link text] (non-greedy) + -- %[(.-)%] matches [label] and captures the label content + local start_pos = 1 + while start_pos <= #line do + local match_start, match_end, label = string.find(line, "%[.-%]%[(.-)%]", start_pos) + if not match_start then + break + end + + if label and label ~= "" and not seen[label] then + table.insert(labels, label) + seen[label] = true + end + + start_pos = match_end + 1 + end + end + + return labels +end + +local function count_consecutive_spaces(str) + -- Remove leading spaces first + local trimmed = str:match("^%s*(.*)") + local count = 0 + + -- Count each sequence of one or more consecutive spaces + for spaces in trimmed:gmatch("%s+") do + count = count + 1 + end + return count +end + +vim.api.nvim_buf_create_user_command(0, "AddRef", function(opts) + local args = vim.split(opts.args, " ", { trimempty = true }) + if #args < 2 then + vim.print("Usage: :AddRef