Am a long time kate user switching to vim.
Wonder whether vim has an easily activable option (or for it has been coded a plugin) to 'smartly' apply static word wrap to large strings when coding major languages: C/C++, Java, Python, PHP, (more follow).
Not only while writing but also while applying an indentation modification to a visual text block, or (un)?commenting it. Let us have a pseudo-Java situation like:
1 String loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipi" +
2 "sicing elit, sed do eiusmod tempor incididunt ut " +
3 "labore et dolore magna aliqua. Ut enim ad minim v" +
4 "eniam, quis nostrud exercitation ullamco laboris " +
5 "nisi ut aliquip ex ea commodo consequat. Duis aut" +
6 "e irure dolor in reprehenderit in voluptate velit" +
7 " esse cillum dolore eu fugiat nulla pariatur. Exc" +
8 "epteur sint occaecat cupidatat non proident, sunt" +
9 " in culpa qui officia deserunt mollit anim id est" +
10 " laborum.";
~
At some point would want to add or remove some indentation levels, but relying in the editor to rebuild the whole language provisioned string with our static word wrap rules. Suppose now by some reason it is desirable to remove two spaces of indentation, the desired output would be:
1 String loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisi" +
2 "cing elit, sed do eiusmod tempor incididunt ut labo" +
3 "re et dolore magna aliqua. Ut enim ad minim veniam," +
4 " quis nostrud exercitation ullamco laboris nisi ut " +
5 "aliquip ex ea commodo consequat. Duis aute irure do" +
6 "lor in reprehenderit in voluptate velit esse cillum" +
7 " dolore eu fugiat nulla pariatur. Excepteur sint oc" +
8 "caeact cupidatat non proident, sunt in culpa qui of" +
9 "ficia deserunt mollit anim id est laborum.";
~
Which is the tool for this to be constructed by vim?
With Vim, the gq command reformats lines; this can even be done as-you-type with :set formatoptions+=a.
Unfortunately, Vim's built-in capabilities are limited to basic stuff (see :help fo-table); elaborate and language-specific formatters are meant to be provided by external programs ('formatprg'), or Vimscript ('formatexpr'), the latter one I haven't actually seen used yet.
So, if you're lucky you'll find an external code formatter program that can be integrated, or you'll have to write such a thing yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With