I am using Vim to edit LaTeX documents. I know I can use :set linebreak
to prevent Vim from breaking lines in the middle of a word, but this works globally.
Is there a way to have line breaking respect word boundaries on text, but not break wherever in code?
For example if I have a line:
The discussed algorithm is given in pseudo code in \Cref{alg_main_pseudocode}.
I don't mind the text being broken in the middle of the reference command, but I would prefer the text itself be unbroken.
Is something like this even possible? It seems like it might be, since Vim can obviously differentiate code from text (something like this works for spell check at least)
EDIT: for clarification, I want Vim to not visually break lines in the middle of words in text, but keep breaking them in the middle of words in code (as in LaTex code, stuff like equations, commands etc.). What I want to achieve is purely visual, only to change the way Vim displays the file.
Images to show what I want:
This is without :set linebreak
. As you can see, the words are broken wherever the line happens to end.
This is with :set linebreak
. As you can see, the lines are broken on white spaces.
I want something in between, for the text words to not be broken, and for the tex code to be broken. For example, (going by the first Image), I want the word system not to be broken, but the command \MotionEqs
to be broken; and so on for the whole file. (Both the images show the same single line being displayed)
Purely visual aspect of the editor, without changing the file in question.
breakat
option (like:set breakat+=\\${}
) but this will not be aware of context and also look ugly. I'd take advantage of the fact that LaTeX mostly ignores whitespace and add a lot of newlines into the source. Makes it easier to read and easier to edit.