From e5dfb045b994e1ab8fef9ef5d3f02ce20ea6b685 Mon Sep 17 00:00:00 2001 From: Ryan Kavanagh Date: Mon, 13 Dec 2021 16:55:42 -0500 Subject: many more renames --- dot_vim/ftplugin/latex-suite/brackets.vim | 145 ++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 dot_vim/ftplugin/latex-suite/brackets.vim (limited to 'dot_vim/ftplugin/latex-suite/brackets.vim') diff --git a/dot_vim/ftplugin/latex-suite/brackets.vim b/dot_vim/ftplugin/latex-suite/brackets.vim new file mode 100644 index 0000000..0669ce4 --- /dev/null +++ b/dot_vim/ftplugin/latex-suite/brackets.vim @@ -0,0 +1,145 @@ +" ============================================================================== +" History: This was originally part of auctex.vim by Carl Mueller. +" Srinath Avadhanula incorporated it into latex-suite with +" significant modifications. +" Parts of this file may be copyrighted by others as noted. +" CVS: $Id: brackets.vim 997 2006-03-20 09:45:45Z srinathava $ +" Description: +" This ftplugin provides the following maps: +" . encloses the previous character in \mathbf{} +" . is polymorphic as follows: +" Insert mode: +" 1. If the previous character is a letter or number, then capitalize it and +" enclose it in \mathcal{} +" 2. otherwise insert \cite{} +" Visual Mode: +" 1. Enclose selection in \mathcal{} +" . is also polymorphic as follows: +" If the character before typing is one of '([{| \left(\right +" similarly for [, | +" { \left\{\right\} +" 2. < \langle\rangle +" 3. q \lefteqn{} +" otherwise insert \label{} +" . inserts \item commands at the current cursor location depending on +" the surrounding environment. For example, inside itemize, it will +" insert a simple \item, but within a description, it will insert +" \item[<+label+>] etc. +" +" These functions make it extremeley easy to do all the \left \right stuff in +" latex. +" ============================================================================== + +" Avoid reinclusion. +if exists('b:did_brackets') + finish +endif +let b:did_brackets = 1 + +" define the funtions only once. +if exists('*Tex_MathBF') + finish +endif + +" Tex_MathBF: encloses te previous letter/number in \mathbf{} {{{ +" Description: +function! Tex_MathBF() + return "\\\mathbf{\}" +endfunction " }}} +" Tex_MathCal: enclose the previous letter/number in \mathcal {{{ +" Description: +" if the last character is not a letter/number, then insert \cite{} +function! Tex_MathCal() + let line = getline(line(".")) + let char = line[col(".")-2] + + if char =~ '[a-zA-Z0-9]' + return "\".'\mathcal{'.toupper(char).'}' + else + return IMAP_PutTextWithMovement('\cite{<++>}<++>') + endif +endfunction +" }}} +" Tex_LeftRight: maps in insert mode. {{{ +" Description: +" This is a polymorphic function, which maps the behaviour of in the +" following way: +" If the character before typing is one of '([{| \left(<++>\right<++> +" similarly for [, | +" { \left\{<++>\right\}<++> +" 2. < \langle<++>\rangle<++> +" 3. q \lefteqn{<++>}<++> +" otherwise insert \label{<++>}<++> +function! Tex_LeftRight() + let line = getline(line(".")) + let char = line[col(".")-2] + let previous = line[col(".")-3] + + let matchedbrackets = '()[]{}||' + if char =~ '(\|\[\|{\||' + let add = '' + if char =~ '{' + let add = "\\" + endif + let rhs = matchstr(matchedbrackets, char.'\zs.\ze') + return "\".IMAP_PutTextWithMovement('\left'.add.char.'<++>\right'.add.rhs.'<++>') + elseif char == '<' + return "\".IMAP_PutTextWithMovement('langle<++>\rangle<++>') + elseif char == 'q' + return "\".IMAP_PutTextWithMovement('\lefteqn{<++>}<++>') + else + return IMAP_PutTextWithMovement('\label{<++>}<++>') + endif +endfunction " }}} +" Tex_PutLeftRight: maps in normal mode {{{ +" Description: +" Put \left...\right in front of the matched brackets. +function! Tex_PutLeftRight() + let previous = getline(line("."))[col(".") - 2] + let char = getline(line("."))[col(".") - 1] + if previous == '\' + if char == '{' + exe "normal ileft\\\l%iright\\\l%" + elseif char == '}' + exe "normal iright\\\l%ileft\\\l%" + endif + elseif char =~ '\[\|(' + exe "normal i\\left\l%i\\right\l%" + elseif char =~ '\]\|)' + exe "normal i\\right\l%i\\left\l%" + endif +endfunction " }}} + +" Provide 'd mapping for easy user customization. {{{ +inoremap Tex_MathBF =Tex_MathBF() +inoremap Tex_MathCal =Tex_MathCal() +inoremap Tex_LeftRight =Tex_LeftRight() +vnoremap Tex_MathBF `>a}` +vnoremap Tex_MathCal `>a}` +nnoremap Tex_LeftRight :call Tex_PutLeftRight() + +" }}} +" Tex_SetBracketingMaps: create mappings for the current buffer {{{ +function! Tex_SetBracketingMaps() + + call Tex_MakeMap('', 'Tex_MathBF', 'i', ' ') + call Tex_MakeMap('', 'Tex_MathCal', 'i', ' ') + call Tex_MakeMap('', 'Tex_LeftRight', 'i', ' ') + call Tex_MakeMap('', 'Tex_MathBF', 'v', ' ') + call Tex_MakeMap('', 'Tex_MathCal', 'v', ' ') + call Tex_MakeMap('', 'Tex_LeftRight', 'n', ' ') + +endfunction +" }}} + +augroup LatexSuite + au LatexSuite User LatexSuiteFileType + \ call Tex_Debug('brackets.vim: Catching LatexSuiteFileType event', 'brak') | + \ call Tex_SetBracketingMaps() +augroup END + +" vim:fdm=marker -- cgit v1.2.3