This commit is contained in:
root
2025-08-10 20:24:22 +00:00
commit f470e78d1c
75 changed files with 4408 additions and 0 deletions

35
after/ftplugin/cpp.vim Normal file
View File

@@ -0,0 +1,35 @@
set commentstring=//\ %s
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r
nnoremap <silent> <buffer> <F9> :call <SID>compile_run_cpp()<CR>
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

View File

@@ -0,0 +1 @@
set commentstring=#\ %s

View File

@@ -0,0 +1,3 @@
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r

6
after/ftplugin/lua.vim Normal file
View File

@@ -0,0 +1,6 @@
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r
nnoremap <buffer><silent> <F9> :luafile %<CR>
nnoremap <buffer><silent> <space>f <cmd>silent !stylua %<CR>

View File

@@ -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*<!%-%-.*[Rr]eferences.*%-%->[%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, "<!-- References -->")
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 <label> <url>")
return
end
local label = args[1]
local url = args[2]
add_reference_at_end(label, url, "")
end, {
desc = "Add reference link at buffer end",
nargs = "+",
complete = function(arg_lead, cmdline, curpos)
vim.print(string.format("arg_lead: '%s', cmdline: '%s', curpos: %d", arg_lead, cmdline, curpos))
if count_consecutive_spaces(cmdline) > 1 then
return {}
end
local ref_link_labels = get_ref_link_labels()
return ref_link_labels
end,
})

View File

@@ -0,0 +1,67 @@
set concealcursor=c
set wrap
" Fix minor issue with footnote, see https://github.com/vim-pandoc/vim-markdownfootnotes/issues/22
if exists(':FootnoteNumber')
nnoremap <buffer><silent> ^^ :<C-U>call markdownfootnotes#VimFootnotes('i')<CR>
inoremap <buffer><silent> ^^ <C-O>:<C-U>call markdownfootnotes#VimFootnotes('i')<CR>
imap <buffer> <silent> @@ <Plug>ReturnFromFootnote
nmap <buffer> <silent> @@ <Plug>ReturnFromFootnote
endif
" Text objects for Markdown code blocks
xnoremap <buffer><silent> ic :<C-U>call text_obj#MdCodeBlock('i')<CR>
xnoremap <buffer><silent> ac :<C-U>call text_obj#MdCodeBlock('a')<CR>
onoremap <buffer><silent> ic :<C-U>call text_obj#MdCodeBlock('i')<CR>
onoremap <buffer><silent> ac :<C-U>call text_obj#MdCodeBlock('a')<CR>
" Use + to turn several lines into an unorderd list
" Ref: https://vi.stackexchange.com/q/5495/15292 and https://stackoverflow.com/q/42438795/6064933
nnoremap <buffer><silent> + :set operatorfunc=AddListSymbol<CR>g@
xnoremap <buffer><silent> + :<C-U> call AddListSymbol(visualmode(), 1)<CR>
function! AddListSymbol(type, ...) abort
if a:0
let line_start = line("'<")
let line_end = line("'>")
else
let line_start = line("'[")
let line_end = line("']")
endif
" add list symbol to each line
for line in range(line_start, line_end)
let text = getline(line)
let l:end = matchend(text, '^\s*')
if l:end == 0
let new_text = '+ ' . text
else
let new_text = text[0 : l:end-1] . ' + ' . text[l:end :]
endif
call setline(line, new_text)
endfor
endfunction
" Add hard line breaks for Markdown
nnoremap <buffer><silent> \ :set operatorfunc=AddLineBreak<CR>g@
xnoremap <buffer><silent> \ :<C-U> call AddLineBreak(visualmode(), 1)<CR>
function! AddLineBreak(type, ...) abort
if a:0
let line_start = line("'<")
let line_end = line("'>")
else
let line_start = line("'[")
let line_end = line("']")
endif
for line in range(line_start, line_end)
let text = getline(line)
" add backslash to each line
let new_text = text . "\\"
call setline(line, new_text)
endfor
endfunction

16
after/ftplugin/python.vim Normal file
View File

@@ -0,0 +1,16 @@
if exists(':AsyncRun')
nnoremap <buffer><silent> <F9> :<C-U>AsyncRun python -u "%"<CR>
endif
" Do not wrap Python source code.
set nowrap
set sidescroll=5
set sidescrolloff=2
set colorcolumn=100
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
nnoremap <buffer><silent> <space>f <cmd>silent !black %<CR>

6
after/ftplugin/qf.vim Normal file
View File

@@ -0,0 +1,6 @@
" Set quickfix window height, see also https://github.com/lervag/vimtex/issues/1127
function! AdjustWindowHeight(minheight, maxheight)
execute max([a:minheight, min([line('$'), a:maxheight])]), 'wincmd _'
endfunction
call AdjustWindowHeight(5, 15)

1
after/ftplugin/sql.vim Normal file
View File

@@ -0,0 +1 @@
set commentstring=--\ %s

2
after/ftplugin/tex.lua Normal file
View File

@@ -0,0 +1,2 @@
vim.o.textwidth = 120
vim.o.wrap = true

1
after/ftplugin/text.vim Normal file
View File

@@ -0,0 +1 @@
set colorcolumn=

12
after/ftplugin/vim.vim Normal file
View File

@@ -0,0 +1,12 @@
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r
" Set the folding related options for vimscript. Setting folding option in
" modeline is annoying in that the modeline gets executed each time the window
" focus is lost
set foldmethod=expr foldexpr=utils#VimFolds(v:lnum) foldtext=utils#MyFoldText()
set keywordprg=:help
nnoremap <buffer><silent> <F9> :source %<CR>

4
after/ftplugin/yaml.vim Normal file
View File

@@ -0,0 +1,4 @@
" Turn off syntax highlighting for large YAML files
if line('$') > 500
setlocal syntax=OFF
endif