robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Eisuke Kawashimadocs: adjust modelines for HTML rendering #396497e778205ab

master
28.9 KiB836 linesraw
1*usr_10.txt*	Nvim
2
3
4		     VIM USER MANUAL	by Bram Moolenaar
5
6
7			     Making big changes
8
9
10In chapter 4 several ways to make small changes were explained.  This chapter
11goes into making changes that are repeated or can affect a large amount of
12text.  The Visual mode allows doing various things with blocks of text.  Use
13an external program to do really complicated things.
14
15|10.1|	Record and playback commands
16|10.2|	Substitution
17|10.3|	Command ranges
18|10.4|	The global command
19|10.5|	Visual block mode
20|10.6|	Reading and writing part of a file
21|10.7|	Formatting text
22|10.8|	Changing case
23|10.9|	Using an external program
24
25     Next chapter: |usr_11.txt|  Recovering from a crash
26 Previous chapter: |usr_09.txt|  Using the GUI
27Table of contents: |usr_toc.txt|
28
29==============================================================================
30*10.1*	Record and playback commands
31
32The "." command repeats the preceding change.  But what if you want to do
33something more complex than a single change?  That's where command recording
34comes in.  There are three steps:
35
361. The "q{register}" command starts recording keystrokes into the register
37   named {register}.  The register name must be between a and z.
382. Type your commands.
393. To finish recording, press q (without any extra character).
40
41You can now execute the macro by typing the command "@{register}".
42
43Take a look at how to use these commands in practice.  You have a list of
44filenames that look like this:
45
46	stdio.h ~
47	fcntl.h ~
48	unistd.h ~
49	stdlib.h ~
50
51And what you want is the following:
52
53	#include "stdio.h" ~
54	#include "fcntl.h" ~
55	#include "unistd.h" ~
56	#include "stdlib.h" ~
57
58You start by moving to the first character of the first line.  Next you
59execute the following commands:
60
61	qa			Start recording a macro in register a.
62	^			Move to the beginning of the line.
63	i#include "<Esc>	Insert the string #include " at the beginning
64				of the line.
65	$			Move to the end of the line.
66	a"<Esc>			Append the character double quotation mark (")
67				to the end of the line.
68	j			Go to the next line.
69	q			Stop recording the macro.
70
71Now that you have done the work once, you can repeat the change by typing the
72command "@a" three times.
73   The "@a" command can be preceded by a count, which will cause the macro to
74be executed that number of times.  In this case you would type: >
75
76	3@a
77
78
79MOVE AND EXECUTE
80
81You might have the lines you want to change in various places.  Just move the
82cursor to each location and use the "@a" command.  If you have done that once,
83you can do it again with "@@".  That's a bit easier to type.  If you now
84execute register b with "@b", the next "@@" will use register b.
85   If you compare the playback method with using ".", there are several
86differences.  First of all, "." can only repeat one change.  As seen in the
87example above, "@a" can do several changes, and move around as well.
88Secondly, "." can only remember the last change.  Executing a register allows
89you to make any changes and then still use "@a" to replay the recorded
90commands.  Finally, you can use 26 different registers.  Thus you can remember
9126 different command sequences to execute.
92
93
94USING REGISTERS
95
96The registers used for recording are the same ones you used for yank and
97delete commands.  This allows you to mix recording with other commands to
98manipulate the registers.
99   Suppose you have recorded a few commands in register n.  When you execute
100this with "@n" you notice you did something wrong.  You could try recording
101again, but perhaps you will make another mistake.  Instead, use this trick:
102
103	G			Go to the end of the file.
104	o<Esc>			Create an empty line.
105	"np			Put the text from the n register.  You now see
106				the commands you typed as text in the file.
107	{edits}			Change the commands that were wrong.  This is
108				just like editing text.
109	0			Go to the start of the line.
110	"ny$			Yank the corrected commands into the n
111				register.
112	dd			Delete the scratch line.
113
114Now you can execute the corrected commands with "@n".  (If your recorded
115commands include line breaks, adjust the last two items in the example to
116include all the lines.)
117
118
119APPENDING TO A REGISTER
120
121So far we have used a lowercase letter for the register name.  To append to a
122register, use an uppercase letter.
123   Suppose you have recorded a command to change a word to register c.  It
124works properly, but you would like to add a search for the next word to
125change.  This can be done with: >
126
127	qC/word<Enter>q
128
129You start with "qC", which records to the c register and appends.  Thus
130writing to an uppercase register name means to append to the register with
131the same letter, but lowercase.
132
133This works both with recording and with yank and delete commands.  For
134example, you want to collect a sequence of lines into the a register.  Yank
135the first line with: >
136
137	"ayy
138
139Now move to the second line, and type: >
140
141	"Ayy
142
143Repeat this command for all lines.  The a register now contains all those
144lines, in the order you yanked them.
145
146==============================================================================
147*10.2*	Substitution						*find-replace*
148
149The ":substitute" command enables you to perform string replacements on a
150whole range of lines.  The general form of this command is as follows: >
151
152	:[range]substitute/from/to/[flags]
153
154This command changes the "from" string to the "to" string in the lines
155specified with [range].  For example, you can change "Professor" to "Teacher"
156in all lines with the following command: >
157
158	:%substitute/Professor/Teacher/
159<
160	Note:
161	The ":substitute" command is almost never spelled out completely.
162	Most of the time, people use the abbreviated version ":s".  From here
163	on the abbreviation will be used.
164
165The "%" before the command specifies the command works on all lines.  Without
166a range, ":s" only works on the current line.  More about ranges in the next
167section |10.3|.
168
169By default, the ":substitute" command changes only the first occurrence on
170each line.  For example, the preceding command changes the line:
171
172	Professor Smith criticized Professor Johnson today. ~
173
174to:
175
176	Teacher Smith criticized Professor Johnson today. ~
177
178To change every occurrence on the line, you need to add the g (global) flag.
179The command: >
180
181	:%s/Professor/Teacher/g
182
183results in (starting with the original line):
184
185	Teacher Smith criticized Teacher Johnson today. ~
186
187Other flags include p (print), which causes the ":substitute" command to print
188out the last line it changes.  The c (confirm) flag tells ":substitute" to ask
189you for confirmation before it performs each substitution.  Enter the
190following: >
191
192	:%s/Professor/Teacher/c
193
194Vim finds the first occurrence of "Professor" and displays the text it is
195about to change.  You get the following prompt: >
196
197	replace with Teacher? (y)es/(n)o/(a)ll/(q)uit/(l)ast/scroll up(^E)/down(^Y)
198
199At this point, you must enter one of the following answers:
200
201	y		Yes; make this change.
202	n		No; skip this match.
203	a		All; make this change and all remaining ones without
204			further confirmation.
205	q		Quit; don't make any more changes.
206	l		Last; make this change and then quit.
207	CTRL-E		Scroll the text one line up.
208	CTRL-Y		Scroll the text one line down.
209
210
211The "from" part of the substitute command is actually a pattern.  The same
212kind as used for the search command.  For example, this command only
213substitutes "the" when it appears at the start of a line: >
214
215	:s/^the/these/
216
217If you are substituting with a "from" or "to" part that includes a slash, you
218need to put a backslash before it.  A simpler way is to use another character
219instead of the slash.  A plus, for example: >
220
221	:s+one/two+one or two+
222
223==============================================================================
224*10.3*	Command ranges
225
226The ":substitute" command, and many other : commands, can be applied to a
227selection of lines.  This is called a range.
228   The simple form of a range is {number},{number}.  For example: >
229
230	:1,5s/this/that/g
231
232Executes the substitute command on the lines 1 to 5.  Line 5 is included.
233The range is always placed before the command.
234
235A single number can be used to address one specific line: >
236
237	:54s/President/Fool/
238
239Some commands work on the whole file when you do not specify a range.  To make
240them work on the current line the "." address is used.  The ":write" command
241works like that.  Without a range, it writes the whole file.  To make it write
242only the current line into a file: >
243
244	:.write otherfile
245
246The first line always has number one.  How about the last line?  The "$"
247character is used for this.  For example, to substitute in the lines from the
248cursor to the end: >
249
250	:.,$s/yes/no/
251
252The "%" range that we used before, is actually a short way to say "1,$", from
253the first to the last line.
254
255
256USING A PATTERN IN A RANGE
257
258Suppose you are editing a chapter in a book, and want to replace all
259occurrences of "grey" with "gray".  But only in this chapter, not in the next
260one.  You know that only chapter boundaries have the word "Chapter" in the
261first column.  This command will work then: >
262
263	:?^Chapter?,/^Chapter/s=grey=gray=g
264
265You can see a search pattern is used twice.  The first "?^Chapter?" finds the
266line above the current position that matches this pattern.  Thus the ?pattern?
267range is used to search backwards.  Similarly, "/^Chapter/" is used to search
268forward for the start of the next chapter.
269   To avoid confusion with the slashes, the "=" character was used in the
270substitute command here.  A slash or another character would have worked as
271well.
272
273
274ADD AND SUBTRACT
275
276There is a slight error in the above command: If the title of the next chapter
277had included "grey" it would be replaced as well.  Maybe that's what you
278wanted, but what if you didn't?  Then you can specify an offset.
279   To search for a pattern and then use the line above it: >
280
281	/Chapter/-1
282
283You can use any number instead of the 1.  To address the second line below the
284match: >
285
286	/Chapter/+2
287
288The offsets can also be used with the other items in a range.  Look at this
289one: >
290
291	:.+3,$-5
292
293This specifies the range that starts three lines below the cursor and ends
294five lines before the last line in the file.
295
296
297USING MARKS
298
299Instead of figuring out the line numbers of certain positions, remembering
300them and typing them in a range, you can use marks.
301   Place the marks as mentioned in chapter 3.  For example, use "mt" to mark
302the top of an area and "mb" to mark the bottom.  Then you can use this range
303to specify the lines between the marks (including the lines with the marks): >
304
305	:'t,'b
306
307
308VISUAL MODE AND RANGES
309
310You can select text with Visual mode.  If you then press ":" to start a colon
311command, you will see this: >
312
313	:'<,'>
314
315Now you can type the command and it will be applied to the range of lines that
316was visually selected.
317
318	Note:
319	When using Visual mode to select part of a line, or using CTRL-V to
320	select a block of text, the colon commands will still apply to whole
321	lines.  This might change in a future version of Vim.
322
323The '< and '> are actually marks, placed at the start and end of the Visual
324selection.  The marks remain at their position until another Visual selection
325is made.  Thus you can use the "'<" command to jump to position where the
326Visual area started.  And you can mix the marks with other items: >
327
328	:'>,$
329
330This addresses the lines from the end of the Visual area to the end of the
331file.
332
333
334A NUMBER OF LINES
335
336When you know how many lines you want to change, you can type the number and
337then ":".  For example, when you type "5:", you will get: >
338
339	:.,.+4
340
341Now you can type the command you want to use.  It will use the range "."
342(current line) until ".+4" (four lines down).  Thus it spans five lines.
343
344See also |:range|, for an overview of all possible ways to specify a range.
345
346==============================================================================
347*10.4*	The global command
348
349The ":global" command is one of the more powerful features of Vim.  It allows
350you to find a match for a pattern and execute a command there.  The general
351form is: >
352
353	:[range]global/{pattern}/{command}
354
355This is similar to the ":substitute" command.  But, instead of replacing the
356matched text with other text, the command {command} is executed.
357
358	Note:
359	The command executed for ":global" must be one that starts with a
360	colon.  Normal mode commands can not be used directly.  The |:normal|
361	command can do this for you.
362
363Suppose you want to change "foobar" to "barfoo", but only in C++ style
364comments.  These comments start with "//".  Use this command: >
365
366	:g+//+s/foobar/barfoo/g
367
368This starts with ":g".  That is short for ":global", just like ":s" is short
369for ":substitute".  Then the pattern, enclosed in plus characters.  Since the
370pattern we are looking for contains a slash, this uses the plus character to
371separate the pattern.  Next comes the substitute command that changes "foobar"
372into "barfoo".
373   The default range for the global command is the whole file.  Thus no range
374was specified in this example.  This is different from ":substitute", which
375works on one line without a range.
376   The command isn't perfect, since it also matches lines where "//" appears
377halfway through a line, and the substitution will also take place before the
378"//".
379
380Just like with ":substitute", any pattern can be used.  When you learn more
381complicated patterns later, you can use them here.
382
383==============================================================================
384*10.5*	Visual block mode
385
386With CTRL-V you can start selection of a rectangular area of text.  There are
387a few commands that do something special with the text block.
388
389There is something special about using the "$" command in Visual block mode.
390When the last motion command used was "$", all lines in the Visual selection
391will extend until the end of the line, also when the line with the cursor is
392shorter.  This remains effective until you use a motion command that moves the
393cursor horizontally.  Thus using "j" keeps it, "h" stops it.
394
395
396INSERTING TEXT
397
398The command  "I{string}<Esc>" inserts the text {string} in each line, just
399left of the visual block.  You start by pressing CTRL-V to enter visual block
400mode.  Now you move the cursor to define your block.  Next you type I to enter
401Insert mode, followed by the text to insert.  As you type, the text appears on
402the first line only.
403   After you press <Esc> to end the insert, the text will magically be
404inserted in the rest of the lines contained in the visual selection.  Example:
405
406	include one ~
407	include two ~
408	include three ~
409	include four ~
410
411Move the cursor to the "o" of "one" and press CTRL-V.  Move it down with "3j"
412to "four".  You now have a block selection that spans four lines.  Now type: >
413
414	Imain.<Esc>
415
416The result:
417
418	include main.one ~
419	include main.two ~
420	include main.three ~
421	include main.four ~
422
423If the block spans short lines that do not extend into the block, the text is
424not inserted in that line.  For example, make a Visual block selection that
425includes the word "long" in the first and last line of this text, and thus has
426no text selected in the second line:
427
428	This is a long line ~
429	short ~
430	Any other long line ~
431
432		  ^^^^ selected block
433
434Now use the command "Ivery <Esc>".  The result is:
435
436	This is a very long line ~
437	short ~
438	Any other very long line ~
439
440In the short line no text was inserted.
441
442If the string you insert contains a newline, the "I" acts just like a Normal
443insert command and affects only the first line of the block.
444
445The "A" command works the same way, except that it appends after the right
446side of the block.  And it does insert text in a short line.  Thus you can
447make a choice whether you do or don't want to append text to a short line.
448   There is one special case for "A": Select a Visual block and then use "$"
449to make the block extend to the end of each line.  Using "A" now will append
450the text to the end of each line.
451   Using the same example from above, and then typing "$A XXX<Esc>, you get
452this result:
453
454	This is a long line XXX ~
455	short XXX ~
456	Any other long line XXX ~
457
458This really requires using the "$" command.  Vim remembers that it was used.
459Making the same selection by moving the cursor to the end of the longest line
460with other movement commands will not have the same result.
461
462
463CHANGING TEXT
464
465The Visual block "c" command deletes the block and then throws you into Insert
466mode to enable you to type in a string.  The string will be inserted in each
467line in the block.
468   Starting with the same selection of the "long" words as above, then typing
469"c_LONG_<Esc>", you get this:
470
471	This is a _LONG_ line ~
472	short ~
473	Any other _LONG_ line ~
474
475Just like with "I" the short line is not changed.  Also, you can't enter a
476newline in the new text.
477
478The "C" command deletes text from the left edge of the block to the end of
479line.  It then puts you in Insert mode so that you can type in a string,
480which is added to the end of each line.
481   Starting with the same text again, and typing "Cnew text<Esc>" you get:
482
483	This is a new text ~
484	short ~
485	Any other new text ~
486
487Notice that, even though only the "long" word was selected, the text after it
488is deleted as well.  Thus only the location of the left edge of the visual
489block really matters.
490   Again, short lines that do not reach into the block are excluded.
491
492Other commands that change the characters in the block:
493
494	~	swap case	(a -> A and A -> a)
495	U	make uppercase  (a -> A and A -> A)
496	u	make lowercase  (a -> a and A -> a)
497
498
499FILLING WITH A CHARACTER
500
501To fill the whole block with one character, use the "r" command.  Again,
502starting with the same example text from above, and then typing "rx":
503
504	This is a xxxx line ~
505	short ~
506	Any other xxxx line ~
507
508
509	Note:
510	If you want to include characters beyond the end of the line in the
511	block, check out the 'virtualedit' feature in chapter 25.
512
513
514SHIFTING
515
516The command ">" shifts the selected text to the right one shift amount,
517inserting whitespace.  The starting point for this shift is the left edge of
518the visual block.
519   With the same example again, ">" gives this result:
520
521	This is a	  long line ~
522	short ~
523	Any other	  long line ~
524
525The shift amount is specified with the 'shiftwidth' option.  To change it to
526use 4 spaces: >
527
528	:set shiftwidth=4
529
530The "<" command removes one shift amount of whitespace at the left
531edge of the block.  This command is limited by the amount of text that is
532there; so if there is less than a shift amount of whitespace available, it
533removes what it can.
534
535
536JOINING LINES
537
538The "J" command joins all selected lines together into one line.  Thus it
539removes the line breaks.  Actually, the line break, leading white space and
540trailing white space is replaced by one space.  Two spaces are used after a
541line ending (that can be changed with the 'joinspaces' option).
542   Let's use the example that we got so familiar with now.  The result of
543using the "J" command:
544
545	This is a long line short Any other long line ~
546
547The "J" command doesn't require a blockwise selection.  It works with "v" and
548"V" selection in exactly the same way.
549
550If you don't want the white space to be changed, use the "gJ" command.
551
552==============================================================================
553*10.6*	Reading and writing part of a file
554
555When you are writing an e-mail message, you may want to include another file.
556This can be done with the ":read {filename}" command.  The text of the file is
557put below the cursor line.
558   Starting with this text:
559
560	Hi John, ~
561	Here is the diff that fixes the bug: ~
562	Bye, Pierre. ~
563
564Move the cursor to the second line and type: >
565
566	:read patch
567
568The file named "patch" will be inserted, with this result:
569
570	Hi John, ~
571	Here is the diff that fixes the bug: ~
572	2c2 ~
573	<	for (i = 0; i <= length; ++i) ~
574	--- ~
575	>	for (i = 0; i < length; ++i) ~
576	Bye, Pierre. ~
577
578The ":read" command accepts a range.  The file will be put below the last line
579number of this range.  Thus ":$r patch" appends the file "patch" at the end of
580the file.
581   What if you want to read the file above the first line?  This can be done
582with the line number zero.  This line doesn't really exist, you will get an
583error message when using it with most commands.  But this command is allowed:
584>
585	:0read patch
586
587The file "patch" will be put above the first line of the file.
588
589
590WRITING A RANGE OF LINES
591
592To write a range of lines to a file, the ":write" command can be used.
593Without a range it writes the whole file.  With a range only the specified
594lines are written: >
595
596	:.,$write tempo
597
598This writes the lines from the cursor until the end of the file into the file
599"tempo".  If this file already exists you will get an error message.  Vim
600protects you from accidentally overwriting an existing file.  If you know what
601you are doing and want to overwrite the file, append !: >
602
603	:.,$write! tempo
604
605CAREFUL: The ! must follow the ":write" command immediately, without white
606space.  Otherwise it becomes a filter command, which is explained later in
607this chapter.
608
609
610APPENDING TO A FILE
611
612In the first section of this chapter was explained how to collect a number of
613lines into a register.  The same can be done to collect lines in a file.
614Write the first line with this command: >
615
616	:.write collection
617
618Now move the cursor to the second line you want to collect, and type this: >
619
620	:.write >>collection
621
622The ">>" tells Vim the "collection" file is not to be written as a new file,
623but the line must be appended at the end.   You can repeat this as many times
624as you like.
625
626==============================================================================
627*10.7*	Formatting text
628
629When you are typing plain text, it's nice if the length of each line is
630automatically trimmed to fit in the window.  To make this happen while
631inserting text, set the 'textwidth' option: >
632
633	:set textwidth=78
634
635You might remember that in the example vimrc file this command was used for
636every text file.  Thus if you are using that vimrc file, you were already
637using it.  To check the current value of 'textwidth': >
638
639	:set textwidth
640
641Now lines will be broken to take only up to 78 characters.  However, when you
642insert text halfway through a line, or when you delete a few words, the lines
643will get too long or too short.  Vim doesn't automatically reformat the text.
644To tell Vim to format the current paragraph: >
645
646	gqap
647
648This starts with the "gq" command, which is an operator.  Following is "ap",
649the text object that stands for "a paragraph".  A paragraph is separated from
650the next paragraph by an empty line.
651
652	Note:
653	A blank line, which contains white space, does NOT separate
654	paragraphs.  This is hard to notice!
655
656Instead of "ap" you could use any motion or text object.  If your paragraphs
657are properly separated, you can use this command to format the whole file: >
658
659	gggqG
660
661"gg" takes you to the first line, "gq" is the format operator and "G" the
662motion that jumps to the last line.
663
664In case your paragraphs aren't clearly defined, you can format just the lines
665you manually select.  Move the cursor to the first line you want to format.
666Start with the command "gqj".  This formats the current line and the one below
667it.  If the first line was short, words from the next line will be appended.
668If it was too long, words will be moved to the next line.  The cursor moves to
669the second line.  Now you can use "." to repeat the command.  Keep doing this
670until you are at the end of the text you want to format.
671
672==============================================================================
673*10.8*	Changing case
674
675You have text with section headers in lowercase.  You want to make the word
676"section" all uppercase.  Do this with the "gU" operator.  Start with the
677cursor in the first column: >
678
679			     gUw
680<	section header	    ---->      SECTION header
681
682The "gu" operator does exactly the opposite: >
683
684			     guw
685<	SECTION header	    ---->      section header
686
687You can also use "g~" to swap case.  All these are operators, thus they work
688with any motion command, with text objects and in Visual mode.
689   To make an operator work on lines you double it.  The delete operator is
690"d", thus to delete a line you use "dd".  Similarly, "gugu" makes a whole line
691lowercase.  This can be shortened to "guu".  "gUgU" is shortened to "gUU" and
692"g~g~" to "g~~".  Example: >
693
694				g~~
695<	Some GIRLS have Fun    ---->   sOME girls HAVE fUN ~
696
697==============================================================================
698*10.9*	Using an external program
699
700Vim has a very powerful set of commands, it can do anything.  But there may
701still be something that an external command can do better or faster.
702   The command "!{motion}{program}" takes a block of text and filters it
703through an external program.  In other words, it runs the system command
704represented by {program}, giving it the block of text represented by {motion}
705as input.  The output of this command then replaces the selected block.
706   Because this summarizes badly if you are unfamiliar with Unix filters, take
707a look at an example.  The sort command sorts a file.  If you execute the
708following command, the unsorted file input.txt will be sorted and written to
709output.txt.  This works on both Unix and Windows. >
710
711	sort <input.txt >output.txt
712
713Now do the same thing in Vim.  You want to sort lines 1 through 5 of a file.
714You start by putting the cursor on line 1.  Next you execute the following
715command: >
716
717	!5G
718
719The "!" tells Vim that you are performing a filter operation.  The Vim editor
720expects a motion command to follow, indicating which part of the file to
721filter.  The "5G" command tells Vim to go to line 5, so it now knows that it
722is to filter lines 1 (the current line) through 5.
723   In anticipation of the filtering, the cursor drops to the bottom of the
724screen and a ! prompt displays.  You can now type in the name of the filter
725program, in this case "sort".  Therefore, your full command is as follows: >
726
727	!5Gsort<Enter>
728
729The result is that the sort program is run on the first 5 lines.  The output
730of the program replaces these lines.
731
732	line 55			      line 11
733	line 33			      line 22
734	line 11		-->	      line 33
735	line 22			      line 44
736	line 44			      line 55
737	last line		      last line
738
739The "!!" command filters the current line through a filter.  In Unix the
740"date" command prints the current time and date.  "!!date<Enter>" replaces the
741current line with the output of "date".  This is useful to add a timestamp to
742a file.
743
744Note: There is a difference between "!cmd" (e.g. using it without any file
745range) and "{range}!cmd".  While the former will simply execute the external
746command and Vim will show the output, the latter will filter {range}lines
747through the filter and replace that range by the result of the filter command.
748See |:!| and |:range!| for details.
749
750WHEN IT DOESN'T WORK
751
752Starting a shell, sending it text and capturing the output requires that Vim
753knows how the shell works exactly.  When you have problems with filtering,
754check the values of these options:
755
756	'shell'		specifies the program that Vim uses to execute
757			external programs.
758	'shellcmdflag'	argument to pass a command to the shell
759	'shellquote'	quote to be used around the command
760	'shellxquote'	quote to be used around the command and redirection
761	'shellslash'	use forward slashes in the command (only for
762			MS-Windows and alikes)
763	'shellredir'	string used to write the command output into a file
764
765On Unix this is hardly ever a problem, because there are two kinds of shells:
766"sh" like and "csh" like.  Vim checks the 'shell' option and sets related
767options automatically, depending on whether it sees "csh" somewhere in
768'shell'.
769   On MS-Windows, however, there are many different shells and you might have
770to tune the options to make filtering work.  Check the help for the options
771for more information.
772
773
774READING COMMAND OUTPUT
775
776To read the contents of the current directory into the file, use this:
777
778on Unix: >
779	:read !ls
780on MS-Windows: >
781	:read !dir
782
783The output of the "ls" or "dir" command is captured and inserted in the text,
784below the cursor.  This is similar to reading a file, except that the "!" is
785used to tell Vim that a command follows.
786   The command may have arguments.  And a range can be used to tell where Vim
787should put the lines: >
788
789	:0read !date -u
790
791This inserts the current time and date in UTC format at the top of the file.
792(Well, if you have a date command that accepts the "-u" argument.)  Note the
793difference with using "!!date": that replaced a line, while ":read !date" will
794insert a line.
795
796
797WRITING TEXT TO A COMMAND
798
799The Unix command "wc" counts words.  To count the words in the current file: >
800
801	:write !wc
802
803This is the same write command as before, but instead of a file name the "!"
804character is used and the name of an external command.  The written text will
805be passed to the specified command as its standard input.  The output could
806look like this:
807
808       4      47     249 ~
809
810The "wc" command isn't verbose.  This means you have 4 lines, 47 words and 249
811characters.
812
813Watch out for this mistake: >
814
815	:write! wc
816
817This will write the file "wc" in the current directory, with force.  White
818space is important here!
819
820
821REDRAWING THE SCREEN
822
823If the external command produced an error message, the display may have been
824messed up.  Vim is very efficient and only redraws those parts of the screen
825that it knows need redrawing.  But it can't know about what another program
826has written.  To tell Vim to redraw the screen:
827>
828	CTRL-L
829<
830==============================================================================
831
832Next chapter: |usr_11.txt|  Recovering from a crash
833
834Copyright: see |manual-copyright|
835
836vim:tw=78:ts=8:noet:ft=help:norl: