| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- local augroup = vim.api.nvim_create_augroup
- local autocmd = vim.api.nvim_create_autocmd
- -- Fix latex commenting
- augroup("fixLatexComments", { clear = true })
- autocmd("FileType", {
- group = "fixLatexComments",
- pattern = { "plaintex", "tex", "latex" },
- command = "syntax spell toplevel",
- })
- -- Wrap Java at 100 lines
- augroup("wrapJavaAt100LinesException", { clear = true })
- autocmd("FileType", {
- group = "wrapJavaAt100LinesException",
- pattern = "java",
- callback = function()
- vim.opt_local.colorcolumn = "100"
- end,
- })
- -- Markdown Math and Liquid highlighting
- local function math_and_liquid()
- vim.fn.matchadd("math", [[\$\$]])
- vim.fn.matchadd("math_block", [[\$[^$].\{-}\$]])
- vim.fn.matchadd("liquid", [[{%.*%}]])
- vim.fn.matchadd("highlight_block", [[{% highlight .*%}]])
- vim.fn.matchadd("highlight_block", [[```]])
- vim.cmd([[
- hi link math Statement
- hi link liquid Statement
- hi link highlight_block Function
- hi link math_block Function
- ]])
- end
- augroup("callMathFunction", { clear = true })
- autocmd({ "BufRead", "BufNewFile", "BufEnter" }, {
- group = "callMathFunction",
- pattern = { "*.md", "*.markdown" },
- callback = math_and_liquid,
- })
- -- Disable automatic comment
- augroup("disableAutoComment", { clear = true })
- autocmd("FileType", {
- group = "disableAutoComment",
- pattern = "*",
- callback = function()
- vim.opt_local.formatoptions:remove({ "c", "r", "o" })
- end,
- })
- -- Clear TeX build after exiting
- augroup("texclear", { clear = true })
- autocmd("VimLeavePre", {
- group = "texclear",
- pattern = { "*.tex", "*.md" },
- callback = function()
- vim.fn.system('texclear "' .. vim.fn.expand("%") .. '"')
- end,
- })
- -- TI-Basic filetype
- augroup("tibasic", { clear = true })
- autocmd({ "BufNewFile", "BufRead" }, {
- group = "tibasic",
- pattern = { "*.tibasic", "*.tib" },
- callback = function()
- vim.bo.filetype = "python"
- end,
- })
- -- Fern settings
- augroup("OnEnteringFernWindow", { clear = true })
- autocmd("FileType", {
- group = "OnEnteringFernWindow",
- pattern = "fern",
- callback = function()
- vim.api.nvim_buf_set_keymap(0, "n", "<CR>", "<Plug>(fern-action-open:select)", { silent = true })
- -- Add more fern local mappings here if needed
- end,
- })
- -- Emmet Enabler
- augroup("EmmetEnabler", { clear = true })
- autocmd("FileType", {
- group = "EmmetEnabler",
- pattern = { "html", "css" },
- command = "EmmetInstall",
- })
- -- Glyph palette
- augroup("my-glyph-palette", { clear = true })
- autocmd("FileType", {
- group = "my-glyph-palette",
- pattern = { "fern", "startify" },
- callback = function()
- vim.fn["glyph_palette#apply"]()
- end,
- })
- -- Relative line numbers
- augroup("numbertoggle", { clear = true })
- autocmd({ "BufEnter", "FocusGained", "InsertLeave" }, {
- group = "numbertoggle",
- pattern = "*",
- callback = function()
- if vim.opt.number:get() then
- vim.opt.relativenumber = true
- end
- end,
- })
- autocmd({ "BufLeave", "FocusLost", "InsertEnter" }, {
- group = "numbertoggle",
- pattern = "*",
- callback = function()
- if vim.opt.number:get() then
- vim.opt.relativenumber = false
- end
- end,
- })
- -- Vimspector log file fix
- augroup("fixVimSpectorLogFile", { clear = true })
- autocmd("User", {
- group = "fixVimSpectorLogFile",
- pattern = "VimspectorDebugEnded",
- callback = function()
- vim.fn.system("mv ~/.vimspector.log " .. vim.fn.expand("$XDG_CACHE_HOME") .. "/vim/")
- end,
- })
- -- LSP Highlight
- augroup("LspHighlight", { clear = true })
- autocmd("CursorHold", {
- group = "LspHighlight",
- callback = function()
- vim.lsp.buf.document_highlight()
- end,
- })
- autocmd("CursorMoved", {
- group = "LspHighlight",
- callback = function()
- vim.lsp.buf.clear_references()
- end,
- })
- -- TeX Macros
- augroup("texMacros", { clear = true })
- local function map(mode, lhs, rhs, opts)
- opts = opts or {}
- opts.buffer = true
- vim.keymap.set(mode, lhs, rhs, opts)
- end
- autocmd("FileType", {
- group = "texMacros",
- pattern = "tex",
- callback = function()
- map("i", ";beg", "\\begin{<Esc>yypkI\\begin{<Esc>A}<Esc>o<Esc>0i<Esc>jI\\end{<Esc>A}<CR><Esc>0i<CR><Esc>0i<++><Esc>3ki")
- map("i", ";ig", "\\includegraphics[]{<++>}<Esc>6hi")
- map("i", ";tw", "width=\\textwidth<Esc>9hi")
- map("i", ";th", "height=\\textheight<Esc>10hi")
- map("i", ";ni", "\\setlength{\\parindent}{0em}<Esc>")
- map("i", ";ger", "\\usepackage[ngerman]{babel}<Esc>")
- map("i", ";bf", "\\textbf{}<++><Esc>T{i")
- map("i", ";it", "\\textit{}<++><Esc>T{i")
- map("i", ";tt", "\\texttt{}<++><Esc>T{i")
- map("i", ";fr", "\\begin{frame}<CR>\\frametitle{}<CR><++><CR>\\end{frame}<Esc>kklli")
- map("i", ";sw", "\\switchcolumn[]<++><Esc>4hi")
- map("i", ";up", "\\usepackage{}<Esc>i")
- map("i", ";hy", "\\hyphenation{}<Esc>i")
- map("i", ";s1", "\\section{}<Esc>i")
- map("i", ";s2", "\\subsection{}<Esc>i")
- map("i", ";s3", "\\subsubsection{}<Esc>i")
- map("i", ";ap", "\\bibliographystyle{apacite}<CR>\\bibliography{}<Esc>i")
- end,
- })
|