, 내가 직접 만들었습니다. 나는 심도있는 테스트를하지 않았다, 그러나 지금까지 아주 잘 작동하는 것 같다.
" latex_helper.vim
function! GetCustomLatexCommands()
python << EOP
import os
import os.path
import re
def readFile(p):
"""Reads a file and extracts custom commands"""
f = open(p)
commands = []
for _line in f:
line = _line.strip()
# search for included files
tmp = re.search(r"(input|include){(.*)}", line)
if tmp != None:
path = tmp.group(2)
newpath = os.path.join(os.path.dirname(p), path)
if os.path.exists(newpath) and os.path.isfile(newpath):
commands.extend(readFile(newpath))
elif os.path.exists(newpath+".tex") and os.path.isfile(newpath+".tex"):
commands.extend(readFile(newpath+".tex"))
tmp = re.search(r"newcommand{(.*?)}\[(.*?)\]", line)
if tmp != None:
cmd = tmp.group(1)
argc = int(tmp.group(2))
commands.append((cmd[1:], argc))
return commands
def getMain(path, startingpoint = None):
"""Goes folders upwards until it finds a *.latexmain file"""
if startingpoint==None:
startingpoint = path
files = []
if os.path.isdir(path):
files = os.listdir(path)
files = [os.path.join(path, s) for s in files if s.split(".")[-1] == "latexmain"]
if len(files) >= 1:
return os.path.splitext(files[0])[0]
if os.path.dirname(path) != path:
return getMain(os.path.dirname(path), startingpoint)
return startingpoint
def GetCustomLatexCommands():
"""Reads all custom commands and adds them to givm"""
import vim
cmds = readFile(getMain(vim.current.buffer.name))
for (cmd, argc) in cmds:
vim.command('let g:Tex_Com_%s="\\\\%s%s <++>"'%(cmd, cmd, "{<++>}"*argc))
GetCustomLatexCommands()
EOP
endfunction
autocmd BufRead *.tex :call GetCustomLatexCommands()
당신은 \의 mycommand {<++>} {<++>} {<++>} <++>''와'\ mycommand'를 대체하기 위해 자동 대체 규칙을 정의 할 수 있어야한다. 이 빔이 연결이 분명하다해도, 그 자체 라텍스하지에 대해 때문에 어쨌든,이 질문은 자매 사이트 http://superuser.com에 더 잘 될 수 있습니다. –