--- Personal lua config files for NeoVim. -- Last Changed: 2019-01-27 -- Author: Federico Igne -- License: This file is placed in the public domain. local map = require 'dyamon.util.map' local cp = require 'dyamon.util.checkpoint' local bopt = vim.bo local wopt = vim.wo --- {{{1 Utils -- @section utils local function get_TeXroot() local root local header = vim.api.nvim_buf_get_lines(0, 0, 5, false) for _,l in ipairs(header) do local _, _, r = l:find("^%%%s+!TeX%s+root%s+=%s+(%S+)$") root = r or root end return root or "%" end --- {{{1 Options -- @section options -- Set default compiler -- NOTE: this looks for metadata info at the top of the page to set the -- main entry point of the LaTeX project. -- -- % !TeX root = -- -- Falls back to current file (`%`) if the header is not provided. vim.b.TeXroot = get_TeXroot() bopt.makeprg = "latexmk -pdf "..vim.b.TeXroot -- Set soft wrapping bopt.textwidth = 0 -- disable hard wrapping wopt.wrap = true wopt.linebreak = true -- soft wrapping on 'breakat' --- {{{1 Custom vim-surround options -- @section vim-surround vim.b['surround_'..string.byte('"')] = "``\r''" vim.b['surround_'..string.byte('>')] = "\\langle \r \\rangle" vim.b['surround_'..string.byte('p')] = "\\{ \r \\}" vim.b['surround_'..string.byte('E')] = "\\begin{\1Environment: \1}\n\r\n\\end{\1\1}\n" vim.b['surround_'..string.byte('e')] = "\\emph{\r}" vim.b['surround_'..string.byte('i')] = "\\textit{\r}" vim.b['surround_'..string.byte('b')] = "\\textbf{\r}" vim.b['surround_'..string.byte('c')] = "\\texttt{\r}" vim.b['surround_'..string.byte('C')] = "\\cite{\r}" vim.b['surround_'..string.byte('r')] = "\\ref{\r}" vim.b['surround_'..string.byte('m')] = "\\mathcal{\r}" vim.b['surround_'..string.byte('0')] = "\\part{\r}<+\\label{part:<+label+>}+>\n\n" vim.b['surround_'..string.byte('1')] = "\\chapter{\r}<+\\label{chap:<+label+>}+>\n\n" vim.b['surround_'..string.byte('2')] = "\\section{\r}<+\\label{sec:<+label+>}+>\n\n" vim.b['surround_'..string.byte('3')] = "\\subsection{\r}<+\\label{ssec:<+label+>}+>\n\n" vim.b['surround_'..string.byte('4')] = "\\subsubsection{\r}<+\\label{sssec:<+label+>}+>\n\n" vim.b['surround_'..string.byte('5')] = "\\paragraph{\r}<+\\label{par:<+label+>}+>\n\n" --- {{{1 Mappings -- @section mappings cp.surround(";be", "E", 0) cp.surround(";em", "e", 0) cp.surround(";mc", "m", 0) cp.surround(";r", "r", 0) cp.surround(";c", "C", 0) cp.surround(";pt", "0", 0) cp.surround(";ch", "1", 0) cp.surround(";sec", "2", 0) cp.surround(";ssec", "3", 0) cp.surround(";sssec", "4", 0) cp.surround(";pg", "5", 0) cp.surround(";fi", "i", 0) cp.surround(";fb", "b", 0) cp.surround(";fc", "c", 0) cp.surround("$$", "$", 0) cp.surround("\\{}", "p", 0) --- {{{1 Abbreviations -- @section abbreviations vim.cmd [[ " Allows imaps that happen to be one the prefix of another (e.g., <- and <--) function! WrapIAbbr(pat,exp) abort let c = nr2char(getchar(0)) return ((c =~ '\s') ? a:exp : a:pat) . c endfunction " Generic iabbrev \i \item iabbrev .. \dots " Math iabbrev \= =WrapIAbbr('\=','\models') " Arrows iabbrev -> \rightarrow iabbrev --> \longrightarrow iabbrev => \Rightarrow iabbrev ==> \Longleftarrow iabbrev <- =WrapIAbbr('<-','\leftarrow') iabbrev <-- =WrapIAbbr('<--','\longleftarrow') iabbrev <= =WrapIAbbr('<=','\Leftarrow') iabbrev <== =WrapIAbbr('<==','\Longleftarrow') iabbrev <-> \leftrightarrow iabbrev <--> \longleftrightarrow iabbrev <=> \Leftrightarrow iabbrev <==> \Longleftrightarrow iabbrev \-> \mapsto iabbrev \--> \longmapsto iabbrev \=> \Mapsto iabbrev \==> \Longmapsto ]]