vim - The 'gq' command merge comment lines with non-comment lines -


i'm writing latex doc using vim now, , met problem when using 'gq' command format paragraphs. example, if have paragraph this:

some text% comment text 

the result of 'gqap' is:

some text% comment text 

and hope be:

some text% comment text 

however, if comment standalone, 'gq' works fine:

some text % comment text 

gets:

some text % comment text 

i don't know whether bug of vim or not, , don't know how fix it...any help

update:

today have written vim function 'formatexpr' prevent vim break lines ending "%%":

function formattex()     let lnum = v:lnum                             " found v:lnum , v:count may change before exiting function, made copy here     let lcount = v:count     let lb = lnum + lcount - 1     let le = lb     while lb >= lnum                              " process file in inverse order, or have deal line number changes         if match(getline(lb), '%%$') >= 0             if lb < le                 exec "normal! ".(lb + 1)."gzr"    " zr here opens fold, or result may wrong                  exec "normal! gw".le."g"             endif             let le = lb - 1         elseif lb == lnum             if lcount > 1                 exec "normal! ".lb."gzr"                 exec "normal! gw".le."g"             else                 return 1                          " when 'formatoptions' has 'a' flag, branch necessary or cursor jump unpredictable...                                                   " according source code of vim, if return value of 'formatexpr' non-zero, build-in formatter used.             endif         endif         let lb = lb - 1     endwhile     return 0 endfunction 

i hope poor example other guys facing similar problems.

there's hint @ :help format-comments:

vim recognizes comment specific string at start of line (ignoring white space).

though there seems special handling three-piece comments when formatting gq, comments not start @ beginning of line aren't handled well. have limit scope of gq formatting text around comments.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -

java Extracting Zip file -