annotate runtime/doc/usr_25.txt @ 20324:23188ef99fc2 v8.2.0717

patch 8.2.0717: Vim9: postponed constant expressions does not scale Commit: https://github.com/vim/vim/commit/7d131b071539e73e4f8a1e6ffbb4d7bfc69a57ec Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 8 19:10:34 2020 +0200 patch 8.2.0717: Vim9: postponed constant expressions does not scale Problem: Vim9: postponed constant expressions does not scale. Solution: Add a structure to pass around postponed constants.
author Bram Moolenaar <Bram@vim.org>
date Fri, 08 May 2020 19:15:03 +0200
parents af69c9335223
children f8116058ca76
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18879
af69c9335223 Vim 8.2 release
Bram Moolenaar <Bram@vim.org>
parents: 18475
diff changeset
1 *usr_25.txt* For Vim version 8.2. Last change: 2016 Mar 28
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 Editing formatted text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 Text hardly ever comes in one sentence per line. This chapter is about
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 breaking sentences to make them fit on a page and other formatting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 Vim also has useful features for editing single-line paragraphs and tables.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 |25.1| Breaking lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |25.2| Aligning text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |25.3| Indents and tabs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |25.4| Dealing with long lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |25.5| Editing tables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 Next chapter: |usr_26.txt| Repeating
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 Previous chapter: |usr_24.txt| Inserting quickly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 *25.1* Breaking lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 Vim has a number of functions that make dealing with text easier. By default,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 the editor does not perform automatic line breaks. In other words, you have
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 to press <Enter> yourself. This is useful when you are writing programs where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 you want to decide where the line ends. It is not so good when you are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 creating documentation and want the text to be at most 70 character wide.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 If you set the 'textwidth' option, Vim automatically inserts line breaks.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 Suppose, for example, that you want a very narrow column of only 30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 characters. You need to execute the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 :set textwidth=30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 Now you start typing (ruler added):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 1 2 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 12345678901234567890123456789012345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 I taught programming for a whi ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 If you type "l" next, this makes the line longer than the 30-character limit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 When Vim sees this, it inserts a line break and you get the following:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 1 2 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 12345678901234567890123456789012345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 I taught programming for a ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 whil ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 Continuing on, you can type in the rest of the paragraph:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 1 2 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 12345678901234567890123456789012345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 I taught programming for a ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 while. One time, I was stopped ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 by the Fort Worth police, ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 because my homework was too ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 hard. True story. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 You do not have to type newlines; Vim puts them in automatically.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 The 'wrap' option makes Vim display lines with a line break, but this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 doesn't insert a line break in the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 REFORMATTING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 The Vim editor is not a word processor. In a word processor, if you delete
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 something at the beginning of the paragraph, the line breaks are reworked. In
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 Vim they are not; so if you delete the word "programming" from the first line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 all you get is a short line:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 1 2 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 12345678901234567890123456789012345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 I taught for a ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 while. One time, I was stopped ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 by the Fort Worth police, ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 because my homework was too ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 hard. True story. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 This does not look good. To get the paragraph into shape you use the "gq"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 Let's first use this with a Visual selection. Starting from the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 line, type: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 v4jgq
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
5400
173c9c860e42 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 5294
diff changeset
89 "v" to start Visual mode, "4j" to move to the end of the paragraph and then
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 the "gq" operator. The result is:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 1 2 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 12345678901234567890123456789012345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 I taught for a while. One ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 time, I was stopped by the ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 Fort Worth police, because my ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 homework was too hard. True ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 story. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 Note: there is a way to do automatic formatting for specific types of text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 layouts, see |auto-format|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 Since "gq" is an operator, you can use one of the three ways to select the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 text it works on: With Visual mode, with a movement and with a text object.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 The example above could also be done with "gq4j". That's less typing, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 you have to know the line count. A more useful motion command is "}". This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 moves to the end of a paragraph. Thus "gq}" formats from the cursor to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 end of the current paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 A very useful text object to use with "gq" is the paragraph. Try this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 gqap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 "ap" stands for "a-paragraph". This formats the text of one paragraph
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 (separated by empty lines). Also the part before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 If you have your paragraphs separated by empty lines, you can format the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 whole file by typing this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 gggqG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 "gg" to move to the first line, "gqG" to format until the last line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 Warning: If your paragraphs are not properly separated, they will be joined
1256
b8017d61c94e updated for version 7.1
vimboss
parents: 1208
diff changeset
122 together. A common mistake is to have a line with a space or tab. That's a
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 blank line, but not an empty line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 874
diff changeset
125 Vim is able to format more than just plain text. See |fo-table| for how to
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 change this. See the 'joinspaces' option to change the number of spaces used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 after a full stop.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 It is possible to use an external program for formatting. This is useful
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 if your text can't be properly formatted with Vim's builtin command. See the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 'formatprg' option.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 *25.2* Aligning text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 To center a range of lines, use the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 :{range}center [width]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 {range} is the usual command-line range. [width] is an optional line width to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 use for centering. If [width] is not specified, it defaults to the value of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 'textwidth'. (If 'textwidth' is 0, the default is 80.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 For example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 :1,5center 40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 results in the following:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 I taught for a while. One ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 time, I was stopped by the ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 Fort Worth police, because my ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 homework was too hard. True ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 story. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 RIGHT ALIGNMENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 Similarly, the ":right" command right-justifies the text: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 :1,5right 37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 gives this result:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 I taught for a while. One ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 time, I was stopped by the ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 Fort Worth police, because my ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 homework was too hard. True ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 story. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 LEFT ALIGNMENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 Finally there is this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 :{range}left [margin]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 Unlike ":center" and ":right", however, the argument to ":left" is not the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 length of the line. Instead it is the left margin. If it is omitted, the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 text will be put against the left side of the screen (using a zero margin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 would do the same). If it is 5, the text will be indented 5 spaces. For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 example, use these commands: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 :1left 5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 :2,5left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 This results in the following:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 I taught for a while. One ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 time, I was stopped by the ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 Fort Worth police, because my ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 homework was too hard. True ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 story. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 JUSTIFYING TEXT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 Vim has no built-in way of justifying text. However, there is a neat macro
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 package that does the job. To use this package, execute the following
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198
8795
aba2d0a01290 commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
199 :packadd justify
aba2d0a01290 commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
200
aba2d0a01290 commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
201 Or put this line in your |vimrc|: >
aba2d0a01290 commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
202
aba2d0a01290 commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
203 packadd! justify
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 7
diff changeset
205 This Vim script file defines a new visual command "_j". To justify a block of
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 text, highlight the text in Visual mode and then execute "_j".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 Look in the file for more explanations. To go there, do "gf" on this name:
8795
aba2d0a01290 commit https://github.com/vim/vim/commit/7db8f6f4f85e5d0526d23107b2a5e2334dc23354
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
208 $VIMRUNTIME/pack/dist/opt/justify/plugin/justify.vim.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 An alternative is to filter the text through an external program. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 :%!fmt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 *25.3* Indents and tabs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 Indents can be used to make text stand out from the rest. The example texts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 in this manual, for example, are indented by eight spaces or a tab. You would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 normally enter this by typing a tab at the start of each line. Take this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 text:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 the first line ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 the second line ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 This is entered by typing a tab, some text, <Enter>, tab and more text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 The 'autoindent' option inserts indents automatically: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 :set autoindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 When a new line is started it gets the same indent as the previous line. In
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 the above example, the tab after the <Enter> is not needed anymore.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 INCREASING INDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 To increase the amount of indent in a line, use the ">" operator. Often this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 is used as ">>", which adds indent to the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 The amount of indent added is specified with the 'shiftwidth' option. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 default value is 8. To make ">>" insert four spaces worth of indent, for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 example, type this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 :set shiftwidth=4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 When used on the second line of the example text, this is what you get:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 the first line ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 the second line ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 "4>>" will increase the indent of four lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 TABSTOP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 If you want to make indents a multiple of 4, you set 'shiftwidth' to 4. But
1256
b8017d61c94e updated for version 7.1
vimboss
parents: 1208
diff changeset
254 when pressing a <Tab> you still get 8 spaces worth of indent. To change this,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 set the 'softtabstop' option: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 :set softtabstop=4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 This will make the <Tab> key insert 4 spaces worth of indent. If there are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 already four spaces, a <Tab> character is used (saving seven characters in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 file). (If you always want spaces and no tab characters, set the 'expandtab'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 option.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 You could set the 'tabstop' option to 4. However, if you edit the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 file another time, with 'tabstop' set to the default value of 8, it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 will look wrong. In other programs and when printing the indent will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 also be wrong. Therefore it is recommended to keep 'tabstop' at eight
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 all the time. That's the standard value everywhere.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 CHANGING TABS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 You edit a file which was written with a tabstop of 3. In Vim it looks ugly,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 because it uses the normal tabstop value of 8. You can fix this by setting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 'tabstop' to 3. But you have to do this every time you edit this file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 Vim can change the use of tabstops in your file. First, set 'tabstop' to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 make the indents look good, then use the ":retab" command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 :set tabstop=3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 :retab 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 The ":retab" command will change 'tabstop' to 8, while changing the text such
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 that it looks the same. It changes spans of white space into tabs and spaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 for this. You can now write the file. Next time you edit it the indents will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 be right without setting an option.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 Warning: When using ":retab" on a program, it may change white space inside
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 a string constant. Therefore it's a good habit to use "\t" instead of a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 real tab.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 *25.4* Dealing with long lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 Sometimes you will be editing a file that is wider than the number of columns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 in the window. When that occurs, Vim wraps the lines so that everything fits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 on the screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 If you switch the 'wrap' option off, each line in the file shows up as one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 line on the screen. Then the ends of the long lines disappear off the screen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 to the right.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 When you move the cursor to a character that can't be seen, Vim will scroll
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 the text to show it. This is like moving a viewport over the text in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 horizontal direction.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 By default, Vim does not display a horizontal scrollbar in the GUI. If you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 want to enable one, use the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 :set guioptions+=b
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 One horizontal scrollbar will appear at the bottom of the Vim window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 If you don't have a scrollbar or don't want to use it, use these commands to
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
311 scroll the text. The cursor will stay in the same place, but it's moved back
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 into the visible text if necessary.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 zh scroll right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 4zh scroll four characters right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 zH scroll half a window width right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 ze scroll right to put the cursor at the end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 zl scroll left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 4zl scroll four characters left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 zL scroll half a window width left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 zs scroll left to put the cursor at the start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 Let's attempt to show this with one line of text. The cursor is on the "w" of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 "which". The "current window" above the line indicates the text that is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 currently visible. The "window"s below the text indicate the text that is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 visible after the command left of it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 |<-- current window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 some long text, part of which is visible in the window ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 ze |<-- window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 zH |<-- window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 4zh |<-- window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 zh |<-- window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 zl |<-- window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 4zl |<-- window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 zL |<-- window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 zs |<-- window -->|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 MOVING WITH WRAP OFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 When 'wrap' is off and the text has scrolled horizontally, you can use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 following commands to move the cursor to a character you can see. Thus text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 left and right of the window is ignored. These never cause the text to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 scroll:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 g0 to first visible character in this line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 g^ to first non-blank visible character in this line
18475
709c6b0dc78f patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
349 gm to middle of screen line
709c6b0dc78f patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
350 gM to middle of the text in this line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 g$ to last visible character in this line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352
18475
709c6b0dc78f patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
353 |<-- window -->|
709c6b0dc78f patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
354 some long text, part of which is visible in one line ~
709c6b0dc78f patch 8.1.2231: not easy to move to the middle of a text line
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
355 g0 g^ gm gM g$
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 BREAKING AT WORDS *edit-no-break*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 When preparing text for use by another program, you might have to make
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 paragraphs without a line break. A disadvantage of using 'nowrap' is that you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 can't see the whole sentence you are working on. When 'wrap' is on, words are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 broken halfway, which makes them hard to read.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 A good solution for editing this kind of paragraph is setting the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 'linebreak' option. Vim then breaks lines at an appropriate place when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 displaying the line. The text in the file remains unchanged.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 Without 'linebreak' text might look like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 +---------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 |letter generation program for a b|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 |ank. They wanted to send out a s|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 |pecial, personalized letter to th|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 |eir richest 1000 customers. Unfo|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 |rtunately for the programmer, he |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 +---------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 After: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 :set linebreak
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 it looks like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 +---------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 |letter generation program for a |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 |bank. They wanted to send out a |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 |special, personalized letter to |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 |their richest 1000 customers. |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 |Unfortunately for the programmer,|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 +---------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 Related options:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 'breakat' specifies the characters where a break can be inserted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 'showbreak' specifies a string to show at the start of broken line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 Set 'textwidth' to zero to avoid a paragraph to be split.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 MOVING BY VISIBLE LINES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 The "j" and "k" commands move to the next and previous lines. When used on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 a long line, this means moving a lot of screen lines at once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 To move only one screen line, use the "gj" and "gk" commands. When a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 doesn't wrap they do the same as "j" and "k". When the line does wrap, they
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 move to a character displayed one line below or above.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 You might like to use these mappings, which bind these movement commands to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 the cursor keys: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 :map <Up> gk
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 :map <Down> gj
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409
6336
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5400
diff changeset
410 TURNING A PARAGRAPH INTO ONE LINE *edit-paragraph-join*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 If you want to import text into a program like MS-Word, each paragraph should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 be a single line. If your paragraphs are currently separated with empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 lines, this is how you turn each paragraph into a single line: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 :g/./,/^$/join
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 That looks complicated. Let's break it up in pieces:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 :g/./ A ":global" command that finds all lines that contain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 at least one character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 ,/^$/ A range, starting from the current line (the non-empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 line) until an empty line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 join The ":join" command joins the range of lines together
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 into one line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 Starting with this text, containing eight lines broken at column 30:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 +----------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 |A letter generation program |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 |for a bank. They wanted to |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 |send out a special, |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 |personalized letter. |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 |To their richest 1000 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 |customers. Unfortunately for |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 |the programmer, |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 +----------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 You end up with two lines:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 +----------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 |A letter generation program for a |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 |bank. They wanted to send out a s|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 |pecial, personalized letter. |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 |To their richest 1000 customers. |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 |Unfortunately for the programmer, |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 +----------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 Note that this doesn't work when the separating line is blank but not empty;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 when it contains spaces and/or tabs. This command does work with blank lines:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 :g/\S/,/^\s*$/join
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 This still requires a blank or empty line at the end of the file for the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 paragraph to be joined.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 *25.5* Editing tables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 Suppose you are editing a table with four columns:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 nice table test 1 test 2 test 3 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 input A 0.534 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 input B 0.913 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 You need to enter numbers in the third column. You could move to the second
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 line, use "A", enter a lot of spaces and type the text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 For this kind of editing there is a special option: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 set virtualedit=all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 Now you can move the cursor to positions where there isn't any text. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 called "virtual space". Editing a table is a lot easier this way.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 Move the cursor by searching for the header of the last column: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 /test 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 Now press "j" and you are right where you can enter the value for "input A".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 Typing "0.693" results in:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 nice table test 1 test 2 test 3 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 input A 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 input B 0.913 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 Vim has automatically filled the gap in front of the new text for you. Now,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 to enter the next field in this column use "Bj". "B" moves back to the start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 of a white space separated word. Then "j" moves to the place where the next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 field can be entered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 You can move the cursor anywhere in the display, also beyond the end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 of a line. But Vim will not insert spaces there, until you insert a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 character in that position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 COPYING A COLUMN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 You want to add a column, which should be a copy of the third column and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 placed before the "test 1" column. Do this in seven steps:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 1. Move the cursor to the left upper corner of this column, e.g., with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 "/test 3".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 2. Press CTRL-V to start blockwise Visual mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 3. Move the cursor down two lines with "2j". You are now in "virtual space":
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 the "input B" line of the "test 3" column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 4. Move the cursor right, to include the whole column in the selection, plus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 the space that you want between the columns. "9l" should do it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 5. Yank the selected rectangle with "y".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 6. Move the cursor to "test 1", where the new column must be placed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 7. Press "P".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 The result should be:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 nice table test 3 test 1 test 2 test 3 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 input A 0.693 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 input B 0.913 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 Notice that the whole "test 1" column was shifted right, also the line where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 the "test 3" column didn't have text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 Go back to non-virtual cursor movements with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 :set virtualedit=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 VIRTUAL REPLACE MODE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 The disadvantage of using 'virtualedit' is that it "feels" different. You
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 can't recognize tabs or spaces beyond the end of line when moving the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 around. Another method can be used: Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 Suppose you have a line in a table that contains both tabs and other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 characters. Use "rx" on the first tab:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 inp 0.693 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 rx |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 inpx0.693 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 The layout is messed up. To avoid that, use the "gr" command:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 inp 0.693 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 grx |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 inpx 0.693 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 What happens is that the "gr" command makes sure the new character takes the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 right amount of screen space. Extra spaces or tabs are inserted to fill the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 gap. Thus what actually happens is that a tab is replaced by "x" and then
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
555 blanks added to make the text after it keep its place. In this case a
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 tab is inserted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 When you need to replace more than one character, you use the "R" command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 to go to Replace mode (see |04.9|). This messes up the layout and replaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 the wrong characters:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 inp 0 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 R0.786 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 inp 0.78634 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 The "gR" command uses Virtual Replace mode. This preserves the layout:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 inp 0 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 gR0.786 |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 inp 0.786 0.534 0.693 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 Next chapter: |usr_26.txt| Repeating
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582
14519
5c5908e81e93 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 13963
diff changeset
583 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: