Home Explore Blog CI



neovim

1st chunk of `runtime/doc/usr_25.txt`
06dca702d33404269a937580a2b89f0ed361c844451758ed0000000100000fa9
*usr_25.txt*	Nvim

		     VIM USER MANUAL - by Bram Moolenaar

			     Editing formatted text


Text hardly ever comes in one sentence per line.  This chapter is about
breaking sentences to make them fit on a page and other formatting.
Vim also has useful features for editing single-line paragraphs and tables.

|25.1|	Breaking lines
|25.2|	Aligning text
|25.3|	Indents and tabs
|25.4|	Dealing with long lines
|25.5|	Editing tables

     Next chapter: |usr_26.txt|  Repeating
 Previous chapter: |usr_24.txt|  Inserting quickly
Table of contents: |usr_toc.txt|

==============================================================================
*25.1*	Breaking lines

Vim has a number of functions that make dealing with text easier.  By default,
the editor does not perform automatic line breaks.  In other words, you have
to press <Enter> yourself.  This is useful when you are writing programs where
you want to decide where the line ends.  It is not so good when you are
creating documentation and want the text to be at most 70 character wide.
   If you set the 'textwidth' option, Vim automatically inserts line breaks.
Suppose, for example, that you want a very narrow column of only 30
characters.  You need to execute the following command: >

	:set textwidth=30

Now you start typing (ruler added):

		 1	   2	     3
	12345678901234567890123456789012345
	I taught programming for a whi ~

If you type "l" next, this makes the line longer than the 30-character limit.
When Vim sees this, it inserts a line break and you get the following:

		 1	   2	     3
	12345678901234567890123456789012345
	I taught programming for a ~
	whil ~

Continuing on, you can type in the rest of the paragraph:

		 1	   2	     3
	12345678901234567890123456789012345
	I taught programming for a ~
	while. One time, I was stopped ~
	by the Fort Worth police, ~
	because my homework was too ~
	hard. True story. ~

You do not have to type newlines; Vim puts them in automatically.

	Note:
	The 'wrap' option makes Vim display lines with a line break, but this
	doesn't insert a line break in the file.


REFORMATTING

The Vim editor is not a word processor.  In a word processor, if you delete
something at the beginning of the paragraph, the line breaks are reworked.  In
Vim they are not; so if you delete the word "programming" from the first line,
all you get is a short line:

		 1	   2	     3
	12345678901234567890123456789012345
	I taught for a ~
	while. One time, I was stopped ~
	by the Fort Worth police, ~
	because my homework was too ~
	hard. True story. ~

This does not look good.  To get the paragraph into shape you use the "gq"
operator.
   Let's first use this with a Visual selection.  Starting from the first
line, type: >

	v4jgq

"v" to start Visual mode, "4j" to move to the end of the paragraph and then
the "gq" operator.  The result is:

		 1	   2	     3
	12345678901234567890123456789012345
	I taught for a while. One ~
	time, I was stopped by the ~
	Fort Worth police, because my ~
	homework was too hard. True ~
	story. ~

Note: there is a way to do automatic formatting for specific types of text
layouts, see |auto-format|.

Since "gq" is an operator, you can use one of the three ways to select the
text it works on: With Visual mode, with a movement and with a text object.
   The example above could also be done with "gq4j".  That's less typing, but
you have to know the line count.  A more useful motion command is "}".  This
moves to the end of a paragraph.  Thus "gq}" formats from the cursor to the
end of the current paragraph.
   A very useful text object to use with "gq" is the paragraph.  Try this: >

	gqap

"ap" stands for "a-paragraph".  This formats the text of one paragraph
(separated by empty lines).  Also the part before the cursor.
   If you have your paragraphs separated by empty lines, you can format the
whole file by typing this: >

	gggqG

"gg" to move to the first line, "gqG" to format until the last line.
   Warning: If your paragraphs are not properly separated,

Title: Editing Formatted Text in Vim
Summary
This chapter of the Vim user manual focuses on editing formatted text, including breaking lines automatically using the 'textwidth' option, aligning text, managing indents and tabs, dealing with long lines, and editing tables. It explains how to reformat text using the "gq" operator with visual selections, movements, and text objects like paragraphs, and demonstrates how to format entire files. It also warns that the procedure will not work as expected if the paragraphs are not properly separated by empty lines.