1

Vim/neovim's automatic line wrapping feature is great for writing reports in Markdown, but sometimes it kicks in when I don't want it to. Is there a setting somewhere that I can set a regex pattern to disable line wrapping within specific blocks of text? My specific use case is to disable text wrapping within inline LaTeX math blocks so they don't end up spanning multiple lines even if the equation contains spaces.

Example

Before autoformat:

Some really long line of text containing an equation $E = mc^2$, with textwidth set to 56 so that the line will wrap in the middle of the equation.

What I get:

Some really long line of text containing an equation $E
= mc^2$, with textwidth set to 56 so that the line will
wrap in the middle of the equation.

What I want:

Some really long line of text containing an equation 
$E = mc^2$, with textwidth set to 56 so that the line 
will wrap in the middle of the equation.

Related

This post shows how to disable Markdown syntax highlighting within LaTeX math blocks, but the inline math syntax pattern only works for inline math expressions that don't contain a line break. I'd like to disable text wrapping within inline math partly for legibility reasons and partly so that syntax highlighting doesn't break for equations that happen to be at the end of a line.

Emerson Harkin
  • 889
  • 5
  • 13
  • 1
    This question might be related https://stackoverflow.com/questions/19204220/vim-disable-word-wrapping-for-specific-lines The answer suggests writing an ad-hoc autocmd changing global settings. I wish we have a better solution! – Grwlf Aug 13 '23 at 21:31
  • 1
    Another related question and a solution suggesting to implement a function wrapping current line in a custom manner: https://stackoverflow.com/questions/41211133/how-to-prevent-wrapping-string-in-quotes-while-enable-auto-wrap-in-vim – Grwlf Aug 13 '23 at 21:42

0 Answers0