wesanyer
wesanyer

Reputation: 1002

Automatic line break within string literal

When I am programming in Vim, I would like to prevent line breaking within a string literal. In other words, with set textwidth = 80

testVariable = myFunction(a=var1, b=var2, c=var3, text="This should not break to
                      the next line but does", end="this should be on the
                      next line")

should instead wrap as follows:

testVariable = myFunction(a=var1, b=var2, c=var3, text="This should not break to the next line but does",
                          end="this should be on the next line")

Are there vimrc options or plugins that I can use to accomplish this? If it matters, I am programming in python.

Upvotes: 3

Views: 615

Answers (1)

Alexander Batischev
Alexander Batischev

Reputation: 820

There's no built-in way to prevent wrapping in specific cases, but you can certainly make your life easier by adding set formatoptions+=b to your vimrc. 'formatoptions' describe how Vim formats the text. b there means that Vim will only split lines that were shorter than 'textwidth' to begin with.

With that, your workflow will look like this:

  1. Start typing your long string.
  2. When it wraps, quit Insert mode and join it all back into one line (EscapekJ; you know about J, right?).
  3. Keep typing. Vim won't try to wrap this line anymore (unless you trim it back under the limit of 'textwidth'.)

Upvotes: 1

Related Questions