2

To justify text on vim I use :set textwidth=77 and space+v to select and finally gq to justify the text.

This is the result

original:

   Most of the command-line options that you can use with GCC are useful for C programs; when an option is only useful with another language (usually C++), the explanation says so
   explicitly.  If the description for a particular option does not mention a source language, you can use that option with all supported languages.

"justified"

       Most of the command-line options that you can use with GCC are useful
for C programs; when an option is only useful with another language (usually
C++), the explanation says so explicitly.  If the description for a
particular option does not mention a source language, you can use that option
with all supported languages.

I want a text like this

Most of the command-line options that you can use with GCC are useful
for C programs; when an option is only useful with another language (
usually C++), the explanation says so explicitly.  If the description
for a particular option does not mention a source language, you can u
se that option with all supported languages.

Is possible with vim without using external tools like fmt?

6
  • Is the text originally in one line? Do you have leading space? Nov 26, 2023 at 10:01
  • 1
    Is copied from man gcc inserted in text with r ! man gcc
    – elbarna
    Nov 26, 2023 at 10:30
  • 1
    But the double space is in the original text you can remove it with :'<,'>s/ \+/ / but this not justification it is edition ;-) Nov 26, 2023 at 10:42
  • Right I correct my question
    – elbarna
    Nov 26, 2023 at 10:52
  • Thanks for your feedback :-) Nov 26, 2023 at 10:58

1 Answer 1

1

I would do:

:set tw=77

ggShift vG to select the text,

:left to kill the leading spaces,

gv to restore the selection,

gq to wrap the text.

3
  • Is a little better but in the line "If the description for a particular" retain two white spaces, I put the result in my question now
    – elbarna
    Nov 26, 2023 at 10:32
  • The first operation (<) could as well be :%<
    – D. Ben Knoble
    Nov 27, 2023 at 3:05
  • 2
    ggVG< or gg<G will only remove one level of indentation, i.e., remove 'shiftwidth' number of spaces. To remove all leading whitespace, it's better to use :%left. Nov 27, 2023 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.