CONTENTS
[Note: The commands for multiple windows and buffers are explained in
a different file, see vim_win.html]
- Introduction
- Notation
- Starting Vim
- Command line
- Workbench (Amiga only)
- Vim window (Amiga only)
- Initialization
- Suspending
- The viminfo file
- Modes
- Introduction
- Switching from mode to mode
- Insert and Replace mode
- special keys
- special special keys
- 'textwidth' option
- 'expandtab' option
- Replace mode
- Insert mode completion
- Command_line mode
- Command line editing
- Command line completion
- Ex command lines
- Ex command line ranges
- Ex special characters
- The window contents
- Abbreviations
- Digraphs
- Using the mouse
- On-line help
- Editing files
- Introduction
- Editing a file
- The argument list
- Writing and quitting
- Using the QuickFix mode
- Editing binary files
- Automatic commands
- Cursor motions
- Left-right motions
- Up-down motions
- Word motions
- Text object motions
- Text object selection
- Pattern searches
- Various motions
- Scrolling
- Tags and special searches
- Tags
- Identifier searches
- Inserting text
- Deleting text
- Changing text
- Delete and
insert
- Simple
changes
- Complex
changes
- Formatting
text
- Formatting C
programs
- Copying and moving
text
- Visual mode
- Various commands
- Repeating commands
- Single repeats
- Multiple repeats
- Complex repeats
- Undo and redo
- Key mapping
- Recovery after a crash
- The swap file
- Recovery
- Options
- Setting options
- Automatically setting options
- Saving settings
- Options summary
- Terminal information
- Startup
- Terminal options
- Window size
- Slow and fast terminals
- Differences from Vi and Ex
- Missing commands
- Missing options
- Limits
11. Changing text
The following commands can be used to change text, that is delete some text
and insert something else, with one command. They can all be undone. The
non-Ex commands can be repeated with the "." command.
11.1 Delete and insert
- R
- Enter Replace mode: Each character you type replaces
an existing character, starting with the character
under the cursor. Repeat the entered text [count]-1
times.
- ["x]c{motion}
- Delete {motion} text [into register x] and start
insert.
- ["x]cc
- Delete [count] lines [into register x] and start
insert (linewise). If 'autoindent' is on, preserve
the indent of the first line.
- ["x]C
- Delete from the cursor position to the end of the
line and [count]-1 more lines [into register x], and
start insert. Synonym for c$ (not linewise).
- ["x]s
- Delete [count] characters [into register x] and start
insert (s stands for Substitute). Synonym for "cl"
(not linewise).
- ["x]S
- Delete [count] lines [into register x] and start
insert. Synonym for "cc" (not linewise).
- {Visual}["x]c or
- {Visual}["x]r
- Delete the highlighted text [into register x] and
start insert (see the chapter on
Visual_mode). {not in Vi}
- {Visual}["x]C or
- {Visual}["x]R
- Delete the highlighted lines [into register x] and
start insert (see the chapter on
Visual_mode). {not in Vi}
You can end Insert and Replace mode with <Esc>. See the section "Insert and Replace mode" for the other special characters in these
modes. The effect of [count] takes place after Insert or Replace mode is
exited. When the 'cpoptions' option contains '$', and the change is within one
line, the text is not directly deleted, but a '$' is put at the last deleted
character.
See registers for an explanation of registers.
Replace mode is just like Insert mode, except that for every character you
enter, one character is deleted. If the end of a line is reached, further
characters are appended (just like Insert mode). In Replace mode the
backspace key restores the original text (if there was any) (see section
"Insert and Replace mode" ).
Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is
on a non-blank. This is because "cw" is interpreted as change-word, and a
word does not include the following white space. {Vi: "cw" when on a blank
followed by other blanks changes only the first blank; this is probably a
bug, because "dw" deletes all the blanks}
11.2 Simple changes
- r{char}
- Replace the character under the cursor with {char}. If
{char} is a <CR> or <NL> the character will be
replaced with a line break. Replacing with a real <CR>
can be done by using CTRL-V <CR>. CTRL-V <NL> will
replace with a <Nul>. {Vi: CTRL-V <CR> still replaces
with a line break, cannot replace something with a
<CR>}
If a [count] is given that many characters will be
replaced with [count] {char}s. When {char} is a <CR>
or <NL> only one is inserted. "5r<CR>" replaces five
characters with a single line break;
When replacing with a <CR> or <NL> autoindenting is
done. This works just like deleting the characters
that are replaced and then doing "i<CR><Esc>".
- ~
- 'notildeop' option: switch case of the character
under the cursor and move the cursor to the right.
If a [count] is given do that many characters {Vi:
no count}
- ~{motion}
- 'tildeop' option: switch case of {motion} text. {Vi:
tilde cannot be used as an operator}
- g~{motion}
- switch case of {motion} text. {Not in Vi}
- {Visual}~
- switch case of highlighted text (see the chapter on
Visual_mode). {not in Vi}
- {Visual}U
- Make highlighted text uppercase (see the chapter on
Visual_mode). {not in Vi}
- gU{motion}
- Make {motion} text uppercase. {not in Vi}
- {Visual}u
- Make highlighted text lowercase (see the chapter on
Visual_mode). {not in Vi}
- gu{motion}
- Make {motion} text lowercase. {not in Vi}
- CTRL-A
- Add [count] to the number at or after the cursor.
{not in Vi}
- CTRL-X
- Subtract [count] from the number at or after the
cursor. {not in Vi}
The CTRL-A and CTRL-X commands work for (signed) decimal numbers and
unsigned octal and hexadecimal numbers. Numbers starting with '0x' or '0X'
are assumed to be hexadecimal. To decide whether the hexadecimal number
should be printed uppercase or not, the case of the rightmost letter in the
number is considered. If there is no letter in the current number, the
previously detected case is used. Numbers starting with a '0' are considered
to be octal. Other numbers are decimal and may be preceded with a minus
sign. If the cursor is on a number, that one will be used. Otherwise the
number right of the cursor will be used.
For octal and hexadecimal numbers with leading zeros, the number of
characters in the number remains equal (when possible). When doing CTRL-A on
"0077" it becomes "0100", CTRL-X on "0x0100" becomes "0x00ff". Note that
when there are no leading zeros this does not work, so CTRL-X on "0x100"
results in "0xff". Note that decimal numbers with leading zeros are
impossible, because they are recognized as octal numbers.
The CTRL-A command is very useful in a macro. Example: How to make a
numbered list.
- Create the first entry. The entry should start with a number.
- qa - start recording into buffer 'a'
- Y - yank the entry
- p - put a copy of the entry below the first one
- CTRL-A - increment the number
- q - stop recording
- <count>@a - repeat the yank, put and increment <count> times
- <{motion}
- Shift the {motion} lines one 'shiftwidth' leftwards.
- <<
- Shift [count] lines one 'shiftwidth' leftwards.
- {Visual}<
- Shift the highlighted lines [count] one 'shiftwidth'
leftwards (see the chapter on
Visual_mode). {not in Vi}
- >{motion}
- Shift {motion} lines one 'shiftwidth' rightwards.
- >>
- Shift [count] lines one 'shiftwidth' rightwards.
- {Visual}>
- Shift the highlighted lines [count] 'shiftwidth'
rightwards (see the chapter on
Visual_mode). {not in Vi}
- :[range]<
- Shift [range] lines one 'shiftwidth' left. Repeat '<'
for shifting multiple 'shiftwidth's.
- :[range]< {count}
- Shift {count} lines one 'shiftwidth' left, starting
with [range] (default current line, See Command line_ranges).
Repeat '<' for shifting multiple 'shiftwidth's.
- :[range]le[ft] [indent]
- left align lines in [range]. Sets the indent in the
lines to [indent] (default 0). {not in Vi}
- :[range]>
- Shift {count} [range] lines one 'shiftwidth' right.
Repeat '>' for shifting multiple 'shiftwidth's.
- :[range]> {count}
- Shift {count} lines one 'shiftwidth' right, starting
with [range] (default current line, See Command line_ranges).
Repeat '>' for shifting multiple 'shiftwidth's.
The ">" and "<" commands are handy for changing the indent within programs.
The size of the white space which is inserted or deleted can be set with the
'shiftwidth' option. Normally the 'shiftwidth' option is 8, but you can set it
to e.g. 3 to make smaller indents. The shift leftwards stops when there is no
indent. The shift right does not do anything with empty lines.
If the 'shiftround' option is on, the indent is rounded to a multiple of
'shiftwidth'.
If the 'smartindent' option is on, or 'cindent' is on and 'cinkeys' contains
'#', lines starting with '#' will not be shifted right (they are supposed to
be C preprocessor lines that must stay in column 1).
When the 'expandtab' option is off (this is the default) <Tab>s are used as
much as possible to make the indent. You can use ">><<" to replace an indent
made out of spaces with the same indent made out of <Tab>s (and a few
spaces if necessary). If the 'expandtab' option is on, only spaces are
used. Then you can use ">><<" to replace <Tab>s in the indent by spaces (or
use ":retab!").
To move a line several 'shiftwidth's use the Visual mode or the ":"
commands. For example:
| Vjj4> |
move three lines 4 indents to the right
|
| :<<< |
move current line 3 indents to the left
|
| :>> 5 |
move 5 lines 2 indents to the right
|
| :5>> |
move line 5 2 indents to the right
|
11.3 Complex changes
- !{motion}{filter}
- Filter {motion} text through the external program
{filter}.
- !!{filter}
- Filter [count] lines through the external program
{filter}.
- {Visual}!{filter}
- Filter the highlighted lines through the external
program {filter} (see the chapter on
Visual_mode). {not in Vi}
- :{range}![!]{filter} [!][arg]
- Filter {range} lines through the external program
{filter}. The optional bangs are replaced with the
latest given command. The optional [arg] is
appended. The output of the filter command is
temporaryly saved in a file and then read into the
buffer. The 'shellredir' option is used to write the
output of the filter in the temporary file.
- ={motion}
- Filter {motion} lines through the external program
given with the 'equalprg' option. When the 'equalprg'
option is empty (this is the default), use the
internal formatting function C_indenting.
- ==
- Filter [count] lines through the external program
given with the 'equalprg' option. When the 'equalprg'
option is empty (this is the default), use the
internal formatting function C_indenting.
- {Visual}=
- Filter the highlighted lines through the external
program given with the 'equalprg' option. When the
'equalprg' option is empty (this is the default),
use the internal formatting function C_indenting. (see the chapter on
Visual_mode). {not in Vi}
A filter is a program that accepts text at standard input, changes it in some
way, and sends it to standard output. The commands above can be used to send
some text through a filter. An example of a filter is "sort", which sorts
lines alphabetically. The "indent" program is used to pretty indent C programs
(you need a version of indent that works like a filter, not all versions do
that). The shell, given with the 'shell' option, is used to execute the
command (See also the 'shelltype' option). The filter commands can be redone
with ".". There cannot be a comment (with '"') after the ":!" command.
- :[range]s[ubstitute]/{pattern}/{string}/[g][c][r][p] [count]
- For each line in [range] replace {pattern} with
{string}. See below for the flags.
- :[range]s[ubstitute] [g][c][r] [count]
- :[range]&[g][c][r] [count]
- Repeat last :substitute with same search pattern and
substitute string. The flags may be different (see
below).
- :[range]~[g][c][r] [count]
- Repeat last substitute with same substitute string
but with last used search pattern. This is like
"&r". See explanation for [r] below.
- &
- Synonym for ":s//~/" (repeat last substitute).
- The arguments that can be given to the substitute commands:
- [g]
- All occurrences in the line are replaced. Otherwise only the first
occurrence in the line is replaced. If the 'edcompatible' option is
on this flag is remembered and toggled each time it is used. It is
reset when a new search pattern is given. If the 'gdefault' option
is on, this flag is default on, give the [g] to switch it off.
- [c]
- Each substitute has to be confirmed. The cursor is positioned on the
matching string. You can type:
| 'y' |
to substitute this match
|
| 'n' |
to skip this match
|
| <Esc> |
to skip this match
|
| 'a' |
to substitute this and all remaining matches {not in Vi}
|
| 'q' |
to quit substituting {not in Vi}
|
| CTRL-E |
to scroll the screen up {not in Vi}
|
| CTRL-Y |
to scroll the screen down {not in Vi}.
|
If the 'edcompatible' option is on the [c] flag is remembered and
toggled each time it is used. It is reset when a new search pattern
is given.
- [r]
- When the search pattern is empty use the previously used search
pattern instead of the search pattern from the last substitute or
":global". If the last command that did a search was a substitute or
":global" there is no effect. If the last command was a search
command, like "/", the pattern from that command is used.
- [p]
- Print the line containing the last substitute.
- [count]
- That many lines are are searched, starting with the last line number
in [range] (default current line, See Command line_ranges).
If the {pattern} for the substitute command is empty, the pattern from the
last substitute or ":global" command is used. With the [r] flag the pattern
from the last substitute, ":global" or search command is used.
For compatibility with Vi these two execptions are allowed:
"\/{string}/" and "\?{string}?" do the same as "//{string}/r".
"\&{string}&" does the same as "//{string}/".
Instead of the '/' which surrounds the pattern and replacement string, you
can use any other character, but not an alphanumeric character, '"' or '|'
or '#'. This is useful if you want to include a '/' in the search pattern or
replacement string. Example: ":s+/+//+"
For the definition of a pattern see 6.6, "Pattern searches".
Some characters in {string} have a special meaning:
| magic |
nomagic |
action
|
| & |
\& |
replaced with the whole matched pattern
|
| \& |
& |
replaced with &
|
| |
\0 |
replaced with the whole matched pattern
|
| |
\1 |
replaced with the matched pattern in the first pair of ()
|
| |
\2 |
replaced with the matched pattern in the second pair of ()
|
| |
.. |
..
|
| |
\9 |
replaced with the matched pattern in the ninth pair of ()
|
| ~ |
\~ |
replaced with the {string} of the previous substitute
|
| \~ |
~ |
replaced with ~
|
| |
\u |
next character made uppercase
|
| |
\U |
following characters made uppercase
|
| |
\l |
next character made lowercase
|
| |
\L |
following characters made lowercase
|
| |
\e |
end of /u, /U, /l and /L
|
| |
\E |
end of /u, /U, /l and /L
|
| |
<CR> |
split line in two at this point
|
| |
\r |
idem
|
| |
\n |
<NL>
|
|
\b |
<BS>
|
| |
\t |
<Tab>
|
|
CTRL-V <CR> |
insert a carriage-return (CTRL-M)
|
Examples:
| :s/a\|b/xxx\0xxx/g |
modifies "a b" in "xxxaxxx xxxbxxx"
|
| :s/\([abc]\)\([efg]\)/\2\1/g |
modifies "af fa bg" in "fa fa gb"
|
| :s/abcde/abc^Mde/ |
modifies "abcde" in "abc", "de" (two lines)
|
| :s/$/^V^M/ |
modifies "abcde" in "abcde^M"
|
Note: To insert a ^M you have to type CTRL-V <CR>. To insert a ^V you have
to type CTRL-V CTRL-V. So to insert the ^V^M in the last example you have to
type CTRL-V CTRL-V CTRL-V <CR>.
Because CTRL-V <CR> inserts a <CR>, it is impossible to insert a CTRL-V just
in front of a line break. You will have to split it up in two parts:
:s/foo/^Vxxxx/
:s/xxxx/^M/
When using parentheses in combination with '|', like in \([ab]\)\|\([cd]\),
either the first or second pattern in parentheses did not match, so either
\1 or \2 is empty. Example:
:s/\([ab]\)\|\([cd]\)/\1x/g modifies "a b c d" in "ax bx x x"
- :[range]ret[ab][!] [new_tabstop]
- All sequences of white-space containing a tab are
replaced with new strings of white-space using the new
tabstop value given. If no new tabstop size is
given, the current value of 'tabstop' is used. With
!, strings of normal spaces will also be replace with
tabs where appropriate. With 'expandtab' on, all
tabs will be replaced with the appropriate number of
spaces. This command sets 'tabstop' to the new
value given, and if performed on the whole file,
which is default, should not make any visible
change. Careful: In a C program a inside a
string will also be affected. Use "\t" to avoid this
(that's a good habit anyway). {not in Vi}
11.4 Formatting text
- :[range]ce[nter] [width]
- Center lines in [range] between [width] columns
(default 'textwidth' or 80 when 'textwidth' is 0).
{not in Vi}
- :[range]ri[ght] [width]
- right align lines in [range] at [width] columns
(default 'textwidth' or 80 when 'textwidth' is 0).
{not in Vi}
- :[range]le[ft] [indent]
- left align lines in [range]. Sets the indent in the
lines to [indent] (default 0). {not in Vi}
- Q{motion}
- Format the lines that were moved over. The length of
each line will be restricted to the width given with
the 'textwidth' option. See below. If the
'textwidth' option is 0, the width of the screen is
used (with a maximum of 79). {not in Vi}
- {Visual}Q
- Format the highlighted text. (see the chapter on
Visual_mode). {not in Vi}
Example: To format the current paragraph use "Qp".
After the "Q" command the cursor is left in the line where the motion command
would take the cursor. This allows for the formatting to be repeated with ".".
This works fine with "Qj" (format current and next line) and "Q}" (format
until end of paragraph).
If the 'autoindent' option is on, the indent of the first line is used for
the following lines.
Empty lines are left unchanged (but lines with spaces or tabs are!).
The 'formatprg' option can be set to the name of an external program, which
will be used instead of the internal function. The 'textwidth' and other
options will not be used then.
Comments are formatted in a special way. Normally a comment starts with
special characters, ends with special characters, and each line in between can
start with special characters.
The 'comments' option can be set to a comma separated list of patterns that
can start a comment line. A pattern can include spaces, but not at the start
of the pattern. If a pattern ends in a space, this means that the pattern can
be followed by the end-of-line or any non-zero amount of white space, which is
reproduced on the new line. By default "* " is included, but "*" is not. This
means that "*" must be followed by some white space or end-of-line for it to
be accepted. This avoids a pointer dereference like "*str" to be recognized as
a comment. Also, "# " is included. This means that a line that starts with
"#include" is not recognized as a comment line. But a line that starts with
"# define" is recognized. In C code this is good, because somewhere after this
a "#endif" is needed.
The 'nestedcomments' option can be set to a comma separated list of patterns
that can start a comment line when they occur at least one time. For example
'>' is often used in e-mail reply to show a part that is included from the
original message. In a reply to a reply it becomes "> >".
The 'formatoptions' option can be set to influence the way how comments are
formatted. It is a string option, that may contain any of these letters. The
default is "tcq". Commas can be added for readability.
| letter |
meaning when present in 'formatoptions'
|
| t |
Do text autowrapping using textwidth
|
| c |
Do comment autowrapping using textwidth, inserting the current
comment leader automatically.
|
| r |
Automatically insert the current comment leader after hitting
<return> in insert mode.
|
| o |
Automatically insert the current comment leader after hitting 'o' or
'O' in Normal mode.
|
| q |
Allow formatting of comments with Q. Note that blank lines, or
lines containing only the comment leader will be left untouched. A
new paragraph starts after such a line, or when the comment leader
changes.
|
| 2 |
When formatting text the indent of the second line of a paragraph is
used for the rest of the paragraph. This allows for paragraphs with
a different indent for the first line.
|
| v |
Vi-compatible auto wrapping in insert mode: Only break a line at a
blank that has been entered during the current insert command. (Note:
this is not 100% Vi compatible, Vi has some "unexpected features" or
bugs in this area. It uses the screen column instead of the line
column)
|
| b |
Like 'v', but only auto wrap if a blank has been entered at or before
the wrap margin. If the line was longer than 'textwidth' when the
insert started, or no blank was entered in the current insert before
reaching 'textwidth', there is no auto wrapping.
|
| l |
Long lines are not broken in insert mode: When a line was longer than
'textwidth' when the insert command started it is not automatically
formatted.
|
With 't' and 'c' you can decide when auto-wrapping is done:
value action
| "" |
no automatic formatting, "Q" can be used for manual formatting
|
| "t" |
automatic formatting of text, not for comments
|
| "c" |
automatic formatting for comments, not for text (good for C code)
|
| "tc" |
automatic formatting for text and comments
|
Note that when 'textwidth' is 0, no formatting is done anyway (but the comment
leader is inserted).
Note that when 'paste' is on, no formatting is done at all.
Note that 'textwidth' can be non-zero even though auto-wrapping never occurs.
This is good because it can be used for formatting only in this case (with
"Q").
If "/*", "*" and "*/" are in the 'comments' variable, then Vim has some
built in stuff to treat these types of comments a bit more cleverly.
Opening a new line before or after "/*" or "*/" (with 'r' or 'o' present in
'formatoptions') gives the correct start of the line automatically. The same
happens with formatting and auto-wrapping. Opening a line after a line
starting with "/*" or "*" and containing "*/", will cause no comment leader to
be inserted, and the indent of the new line is taken from the line containing
the start of the comment.
Eg:
/*
* Your typical comment.
*/
The indent on this line is the same as the start of the above
comment.
All this should be really cool, especially in conjunction with the new
:autocmd command to prepare different settings for different types of file.
Some examples:
| for C code: |
fo="croq" |
(only format comments)
|
| for Mail/news: |
fo="tcrq" |
(format all, don't start comment with "o" command)
|
11.5 Indenting C programs
C programs can be automatically indented. Only the indent is set, no other
formatting is done. To format comments see format_comments.
There are in fact three methods that can be used.
| 'autoindent' |
Just takes the indent from the previous line.
|
| 'smartindent' |
Is like 'autoindent' but also recognizes some C syntax to
increase/reduce the indent where appropriate.
|
| 'cindent' |
Works more clever than the other two and can be configured to
different indenting styles.
|
The rest of this section is about the 'cindent' option.
Note that the indenting done with 'cindent' does not work for 100%. Vim is
not a C compiler, not all syntax is recognized.
Four options are used for C program indenting:
| 'cindent' |
When on automatic C program indenting is enabled.
|
| 'cinkeys' |
Keys that trigger reindenting in insert mode.
|
| 'cinoptions' |
For setting your preferred indent style.
|
| 'cinwords' |
Defines keywords that start an extra indent in the next line.
|
If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using
this algorithm rather than calling an external program.
See autocommand for how to automatically set the 'cindent' option for C code
files and reset it for others.
The 'cinkeys' option can be set to a string that says when to do indenting.
The default is "0{,0},:,0#,!^F,o,O,e". This means that indenting is done
when:
| "0{" |
typing '{' as the first character in a line
|
| "0{" |
typing '}' as the first character in a line
|
| ":" |
typing ':' anywhere
|
| "0#" |
typing '#' as the first character in a line
|
| "!^F" |
typing CTRL-F, which is not inserted
|
| "o" |
typing a <CR> anywhere and for the "o" command (not in insert
mode!)
|
| "O" |
for the "O" command (not in insert mode!)
|
| "e" |
typing the second 'e' for an "else" at the start of a line
|
Characters that can be prepended:
- '!'
- When the key is preceded with a '!' the key will not be inserted but
will just cause the current line to be reindented. This allows you to
set a command key for reindenting the current line. By default CTRL-F
is used for this. Careful with CTRL-I, you might think that it is a
nice command for Indenting, but it is the same as a <Tab>.
- '*'
- When the key is preceded with a '*' the reindenting will be done
before inserting the key. If you use "*<Return>" this means that the
current line will be reindented, before opening a new line.
When the key is not preceded with a '!' or '*' the reindenting will be done
after inserting the key. So ';' will set the indentation of the line
including the ';'.
- '0'
- When a zero is used before the key (but after '!' or '*') it will only
trigger reindenting if the key is the first character typed in the
line.
Special key names:
- <>
- Angle brackets mean spelled-out names of keys. For example: "<Up>",
"<Ins>".
- '^'
- Letters preceded by a caret (^) are control characters. For example:
"^F" is CTRL-F.
- 'o'
- Means to reindent a line for the "o" command and whenever a new
line is opened below the current one. This includes hitting <Return>
in insert mode.
- 'O'
- Means to reindent a line for the "O" command.
- 'e'
- Means to reindent a line that starts with "else" when an 'e' is
inserted.
If you really want to reindent when you type 'o', 'O', 'e', '0', '<', '>', '*'
or '!', use "<o>", "<O>", "<e>", "<0>", "<<>", "<>>", "<*>" or "<!>",
respectively, for those keys.
For an emacs-style indent mode, where lines aren't indented every time you
press Return but only if you press Tab, I suggest:
:set cinkeys=0{,0},:,0#,!<Tab>,!^F
Note: When the indent of the current line was changed manually, cindenting
won't be done for any key. This is to avoid re-indenting after you changed
the indent by typing <BS>, <Tab> or <Space> in the indent, or used CTRL-T or
CTRL-D.
How the indenting is done can be set with 'cinoptions'. In the list below,
"N" represents a number of your choice. It can be negative. When there is an
's' after the number, it is multiplied with 'shiftwidth'. "1s" is
'shiftwidth', "2s" is two times 'shiftwidth', etc. A decimal point is allowed
too: "-0.5s" is minus half a 'shiftwidth'. The examples given below assume a
'shiftwidth' of 4.
|
|
The defaults, spelled out in full, would be
cinoptions=>s,e0,n0,f0,{0,}0,^0,:s,=s,ps,ts,+s,(2s,)20,*30
Lines are put in column 1 if:
- It starts with '#' (preprocessor directives), if 'cinkeys' contains '#'.
- It starts with a label (a keyword followed by ':', other than "case" and
"default").
- Any combination of indentations causes the line to have less than 0
indentation.
12. Copying and moving text
-
- "<a-zA-Z0-9.%:-">
- Use register <a-zA-Z0-9.%:-"> for next delete, yank
or put (use uppercase character to append with
delete and yank) (<.%:> only work with put).
-
- :reg[isters]
- Display the contents of all numbered and named
registers. {not in Vi}
- :reg[isters] {arg}
- Display the contents of the numbered and named
registers that are mentioned in {arg}. For example:
:dis 1a
to display registers '1' and 'a'. Spaces are allowed
in {arg}. {not in Vi}
-
- :di[splay] [arg]
- Same as :registers. {not in Vi}
-
- ["x]y{motion}
- Yank {motion} text [into register x].
-
- ["x]yy
- Yank [count] lines [into register x] (linewise).
-
- ["x]Y
- yank [count] lines [into register x] (synonym for
yy, linewise). If you like "Y" to work from the
cursor to the end of line (which is more logical,
but not Vi-compatible) use ":map Y y$".
-
- {Visual}["x]y
- Yank the highlighed text [into register x] (see the
chapter on Visual_mode). {not in Vi}
-
- {Visual}["x]Y
- Yank the highlighted lines [into register x] (see the
chapter on Visual_mode). {not in Vi}
-
- :[range]y[ank] [x]
- Yank [range] lines [into register x].
- :[range]y[ank] [x] {count}
- Yank {count} lines, starting with last line number
in [range] (default: current line, See Command line ranges),
[into register x].
-
- ["x]p
- Put the text [from register x] after the cursor
[count] times. {Vi: no count}
-
- ["x]P or
-
- ["x]<MiddleMouse>
- Put the text [from register x] before the cursor
[count] times. Using the mouse only works when
'mouse' contains 'n' or 'a'. {Vi: no count}
-
- :[line]pu[t] [x]
- Put the text [from register x] after [line] (default
current line).
- :[line]pu[t]! [x]
- Put the text [from register x] before [line] (default
current line).
- ["x]]p or
- ["x]]<MiddleMouse>
- Like "p", but adjust the indent to the current line.
Using the mouse only works when 'mouse' contains 'n'
or 'a'. {not in Vi}
- ["x][P or
- ["x]]P or
- ["x][p or
- ["x][<MiddleMouse>
- Like "P", but adjust the indent to the current line.
Using the mouse only works when 'mouse' contains 'n'
or 'a'. {not in Vi}
These commands can be used to copy text from one place to another. This is
done by first getting the text into a register with a yank, delete or change
command. The register can then be inserted with a put command. All registers
are kept when changing files. Thus you can also use this to move text from
one file to another (the CTRL-^ command is a quick way to toggle between two
files).
The put commands can be repeated with "." (except for :put) and undone. If the
command that was used to get the text into the register was linewise, the
text will be inserted below ("p") or above ("P") the line where the cursor
is. Otherwise the text will be inserted after ("p") or before ("P") the
cursor. With the ":put" command the text will always be inserted in the next
line. You can exchange two characters with the command sequence "xp". You
can exchange two lines with the command sequence "ddp". You can exchange
two words with the command sequence "deep" (start with the cursor in the
blank space before the first word). The "']" or "`]" command can be used
after the put command to move the cursor to the end of the inserted text,
"'[" or "`[" to move the cursor to the start.
If the command that was used to get the text into the register used
blockwise Visual mode, the block of text will be inserted before ("P") or
after ("p") the cursor column, in the current and next lines. Vim will make
the whole block of text start in the same column. Thus the inserted text
looks the same as when it was yanked or deleted. Some <Tab> characters may
be replaced with spaces to make this happen. However, if the width of the
block is not a multiple of a <Tab> width and the text after the inserted
block contains <Tab>s, that text may be misaligned.
There are five types of registers:
The unnamed register is the register where all text deleted with
the "d", "c", "s", "x" commands or copied with the yank "y" command is
placed, regardless of whether or not a specific register was used (e.g.
"xdd). The contents of this register are used by any put command (p or P)
which does not specify a register. Additionally it can be accessed by the
name '"'. This means you have to type two double quotes. {Vi: register
contents lost when changing files, no '"'}
The numbered registers are filled with yank and delete commands.
Numbered register 0 is filled with the last yank command, unless another
register was specified with ["x]. Numbered register 1 is filled with the text
that was deleted by each delete or change command, unless another register was
specified or the text is less than one line (text deleted with "x" or "dw"
will be put in the small delete register). The contents of register 1 are put
in 2, 2 in 3, and so forth. The contents of register 9 are lost. {Vi: numbered
register contents are lost when changing files; register 0 does not exist}
The small delete register is filled with delete commands that delete
less than one line, except when a register was specified with ["x].
The named registers are only filled when you say so. They are named
'a' to 'z' normally. If you use an uppercase letter, the same registers as
with the lower case letter is used, but the text is appended to the previous
register contents. With a lower case letter the previous contents are lost.
The read-only registers are '%', ':' and '.'. They can only be used
with the commands "p", "P" and ":put".
-
- '.'
- Contains the last inserted text (the same as what is inserted
with the insert mode commands CTRL-A and CTRL-@).
-
- '%'
- Contains the name of the current file.
-
- ':'
- Contains the last command line. It can be used with "@:",
this repeats the last command line.
If you use a put command without specifying a register, the register that
was last written to is used (this is also the contents of the unnamed
register). If you are confused, use the ":dis" command to find out what will
be put (all named and numbered registers are displayed; the unnamed register
is labelled '"').
The next three commands always work on whole lines.
- :[range]co[py] {address}
- Copy the lines given by [range] to below the line
given by {address}.
-
- :t
- Synonym for copy.
- :[range]m[ove] {address}
- Move the lines given by [range] to below the line
given by {address}.
Part 1
Part 2
Part 3
Part 4
Part 5
Part 6
Part 7
Part 8
Part 9
Send feedback on this page to Rajesh Kallingal
For Vim version 3.24. Last modification: 1996 Apr 25
|