Skip to content

Instantly share code, notes, and snippets.

@scajanus
Last active September 12, 2015 14:19
Show Gist options
  • Select an option

  • Save scajanus/04ed683d40f204155bf6 to your computer and use it in GitHub Desktop.

Select an option

Save scajanus/04ed683d40f204155bf6 to your computer and use it in GitHub Desktop.
GetTexEnv.vim
function! GetTexEnv()
let s:env = substitute(getline('.'), '^\s*\\begin{\ze', '', '')
return "}\<CR>\<CR>\\end{" . s:env . "}\<Up>"
endfunction
inoremap <expr> } getline('.') =~ '^\s*\\begin{[^}]\+' ? GetTexEnv() : '}'
@moviuro

moviuro commented Sep 12, 2015

Copy link
Copy Markdown

The '^\s*\\begin{\ze', '', '') part looks wrong as \begin is not always on a new line

@Raimondi

Copy link
Copy Markdown

I'd go with '^.*\\begin{\ze\w\+\%#' to anchor the match to the cursor.

Edited the pattern to match everything before the cursor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment