I found the following code on a stackexchange post: 
http://tex.stackexchange.com/questions/1548/intelligent-paragraph-reflowing-in-vim

The code is for environment-aware formatting in LaTeX.

It's not longer working quite the way I want it---I think it is interacting 
with one of my other plugins that has been updated---so I'd like to try to 
modify it. However I don't have a great knowledge of the Vim scripting 
language, so I don't really understand what's going on in the code. Could 
someone explain it to me?

Alternatively/additionally, if you have a good solution for formatting in 
LaTeX, please share!

Here's the code. It's also on the Stackexchange post in case the formatting 
gets messed up:

" Reformat lines (getting the spacing correct) {{{
fun! TeX_fmt()
    if (getline(".") != "")
    let save_cursor = getpos(".")
        let op_wrapscan = &wrapscan
        set nowrapscan
        let par_begin = 
'^\(%D\)\=\s*\($\|\\start\|\\stop\|\\Start\|\\Stop\|\\\(sub\)*section\>\|\\item\>\|\\NC\>\|\\blank\>\|\\noindent\>\)'
        let par_end   = 
'^\(%D\)\=\s*\($\|\\start\|\\stop\|\\Start\|\\Stop\|\\place\|\\\(sub\)*section\>\|\\item\>\|\\NC\>\|\\blank\>\)'
    try
      exe '?'.par_begin.'?+'
    catch /E384/
      1
    endtry
        norm V
    try
      exe '/'.par_end.'/-'
    catch /E385/
      $
    endtry
    norm gq
        let &wrapscan = op_wrapscan
    call setpos('.', save_cursor) 
    endif
endfun

nmap Q :call TeX_fmt()<CR>

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to