現在、vim を使用して LaTeX ドキュメントを作成していますが、「gq」コマンドを使用して段落をフォーマットするときに問題が発生しました。たとえば、次のような段落があるとします。
some
text% this is a comment
some
text
「gqap」の結果は次のとおりです。
some text% this is a comment some text
そして、それが次のようになることを願っています:
some text% this is a comment
some text
ただし、コメントがスタンドアロンの場合、「gq」は正常に機能します。
some
text
% this is a comment
some
text
取得:
some text
% this is a comment
some text
それがvimのバグかどうかわからないだけで、修正方法もわかりません...何か助けてください
アップデート:
今日、「%%」で終わる vim 改行を防ぐために、「formatexpr」の vim 関数を作成しました。
function FormatTeX()
let lnum = v:lnum " I found that v:lnum and v:count may change before exiting this function, so I made a copy here
let lcount = v:count
let lb = lnum + lcount - 1
let le = lb
while lb >= lnum " process the file in inverse order, or we have to deal with line number changes
if match(getline(lb), '%%$') >= 0
if lb < le
exec "normal! ".(lb + 1)."GzR" " the zR here opens all fold, or the result may be 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 an 'a' flag, this branch is necessary or the cursor will jump unpredictable...
" according to the source code of vim, if the return value of 'formatexpr' is non-zero, the build-in formatter is used.
endif
endif
let lb = lb - 1
endwhile
return 0
endfunction
この貧弱な例が、同様の問題に直面している他の人の助けになることを願っています.