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
6. Cursor motions
These commands move the cursor position. If the new position is off of the
screen, the screen is scrolled to show the cursor (see also 'scrolljump' and
'scrolloff' options).
The motion commands can be used after other commands, called operators, to
have the command operate on the text that was moved over. That is the text
between the cursor position before and after the motion. If the motion
includes a count and the operator also had a count, the two counts are
multiplied. For example: "2d3w" deletes six words.
The operator either affects whole lines, or the characters between
the start and end position. Generally, motions that move between lines
affect lines (are linewise), and motions that move within a line affect
characters. However, there are some exceptions.
A character motion is either inclusive or exclusive. When inclusive,
the start and end position of the motion are included in the operation.
When exclusive, the last character towards the end of the buffer is not
included. Linewise motions always include the start and end position.
Which motions are linewise, inclusive or exclusive is mentioned
below. There are however, two general exceptions:
- If the motion is exclusive and the end of the motion is in column 1, the
end of the motion is moved to the end of the previous line and the motion
becomes inclusive. Example: "}" ends at the first line after a paragraph,
but "V}" will not include that line.
- If the motion is exclusive, the end of the motion is in column 1 and the
start of the motion was at or before the first non-blank in the line, the
motion becomes linewise. Example: If a paragraph begins with some blanks
and you do "d}" while standing on the first non-blank, all the lines of
the paragraph are deleted, including the blanks. If you do a put now, the
deleted lines will be inserted below the cursor position.
Instead of first giving the operator and then a motion you can use Visual
mode: mark the start of the text with "v", move the cursor to the end of the
text that is to be affected and then hit the operator. The text between the
start and the cursor position is highlighted, so you can see what text will
be operated upon. This allows much more freedom, but requires more key
strokes and has limited redo functionality. See the chapter on
Visual_mode.
If you want to know where you are in the file use the "CTRL-G" command
or the "g_CTRL-G" If you set the 'ruler' option,
the cursor position is continuously shown in the status line (which slows down
Vim a little).
NOTE: Experienced users prefer the hjkl keys because they are always right
under their fingers. Beginners often prefer the arrow keys, because they
do not know what the hjkl keys do. The mnemonic value of hjkl is clear from
looking at the keyboard. Think of j as an arrow pointing downwards.
6.1 Left-right motions
- h or
- <Left> or
- CTRL-H or
- <BS>
- [count] characters to the left (exclusive).
Note: If you prefer <BS> to delete a character, use
the mapping:
- :map CTRL-V<BS> X
(to enter "CTRL-V<BS>" type the CTRL-V key, followed
by the <BS> key)
See :fixdel if the <BS> key does not do what you
want.
- l or
- <Right> or
-
- <Space>
- [count] characters to the right (exclusive).
-
- 0
- To the first character of the line (exclusive). When
moving up or down, stay in same screen column (if
possible).
-
- <Home>
- To the first character of the line (exclusive). When
moving up or down, stay in same text column (if
possible). Works like "1|", which differs from "0"
when the line starts with a <Tab>. {not in Vi}
-
- ^
- To the first non-blank character of the line
(exclusive).
-
- $ or <End>
- To the end of line and [count - 1] lines downward
(inclusive).
-
- g0 or g<Home>
- When lines wrap ('wrap on): To the first character of
the screen line (exclusive). Differs from "0" when a
line is wider than the screen.
When lines don't wrap ('wrap' off): To the leftmost
character of the current line that is on the screen.
Differs from "0" when the first character of the line
is not on the screen. {not in Vi}
-
- g^
- When lines wrap ('wrap' on): To the first non-blank
character of the screen line (exclusive). Differs from
"^" when a line is wider than the screen.
When lines don't wrap ('wrap' off): To the leftmost
non-blank character of the current line that is on the
screen. Differs from "^" when the first non-blank
character of the line is not on the screen. {not in
Vi}
-
- g$ or g<End>
- When lines wrap ('wrap' on): To the last character of
the screen line and [count - 1] screen lines downward
(inclusive). Differs from "$" when a line is wider
than the screen.
When lines don't wrap ('wrap' off): To the righmost
character of the current line that is visible on the
screen. Differs from "$" when the last character of
the line is not on the screen or when a count is used.
{not in Vi}
-
- |
- To screen column [count] in the current line
(exclusive).
-
- f{char}
- To [count]'th occurrence of {char} to the right. The
cursor is placed on {char} (inclusive).
-
- F{char}
- To the [count]'th occurrence of {char} to the left.
The cursor is placed on {char} (inclusive).
-
- t{char}
- Till before [count]'th occurrence of {char} to the
right. The cursor is placed on the character left of
{char} (inclusive).
-
- T{char}
- Till after [count]'th occurrence of {char} to the
left. The cursor is placed on the character right of
{char} (inclusive).
-
- ;
- Repeat latest f, t, F or T [count] times.
-
- ,
- Repeat latest f, t, F or T in opposite direction
[count] times.
These commands move the cursor to the specified column in the current line.
They stop at the first column and at the end of the line, except "$", which
may move to one of the next lines. See 'whichwrap' option to make some of the
commands move accross line boundaries.
6.2 Up-down motions
- k or
- <Up> or
-
- CTRL-P
- [count] lines upward (linewise).
- j or
- <Down> or
- CTRL-J or
- <NL> or
-
- CTRL-N
- [count] lines downward (linewise).
- gk or
-
- g<Up>
- [count] display lines upward (exclusive). Differs from
'k' when lines wrap. {not in Vi}
- gj or
-
- g<Down>
- [count] display lines downward (exclusive). Differs
from 'j' when lines wrap. {not in Vi}
-
- - <minus>
- [count] lines upward, on the first non-blank
character (linewise).
- + or
- CTRL-M or
-
- <CR>
- [count] lines downward, on the first non-blank
character (linewise).
-
- _ <underscore>
- [count] - 1 lines downward, on the first non-blank
character (linewise).
- <C-End> or
-
- G
- Goto line [count], default last line, on the first
non-blank character (linewise). If 'startofline' not
set, keep the same column.
- <C-Home> or
-
- gg
- Goto line [count], default first line, on the first
non-blank character (linewise). If 'startofline' not
set, keep the same column.
- :[range]
- Set the cursor on the (last) specified line number
(cannot be used with an operator).
-
- {count}%
- Go to {count} percentage in the file, on the first
non-blank in the line (linewise). To compute the new
line number this formula is used: {count} *
number-of-lines / 100. See also 'startofline'
option. {not in Vi}
These commands move to the specified line. They stop when reaching the first
or the last line. The first two commands put the cursor in the same column
(if possible) as it was after the last command that changed the column,
except after the "$" command, then the cursor will be put on the last
character of the line.
6.3 Word motions
- <S-Right> or
-
- w
- [count] words forward (exclusive).
-
- W
- [count] WORDS forward (exclusive).
-
- e
- Forward to the end of word [count] (inclusive).
-
- E
- Forward to the end of WORD [count] (inclusive).
- <S-Left> or
-
- b
- [count] words backward (exclusive).
-
- B
- [count] WORDS backward (exclusive).
-
- ge
- Backward to the end of word [count] (inclusive).
-
- gE
- Backward to the end of WORD [count] (inclusive).
These commands move over words or WORDS. A word consists of a sequence of
letters, digits and underscores, or a sequence of other non-blank
characters, separated with white space (spaces, tabs, end of line). A WORD
consists of a sequence of non-blank characters, separated with white space.
An empty line is also considered to be a word and a WORD.
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}
Another special case: When using the "w" motion in combination with an
operator and the last word moved over is at the end of a line, the end of
that word becomes the end of the operated text, not the first word in the
next line.
The original Vi implementation of "e" is buggy. For example, the "e" command
will stop on the first character of a line if the previous line was empty.
But when you use "2e" this does not happen. In Vim "ee" and "2e" are the
same, which is more logical. However, this causes a small incompatibility
between Vi and Vim.
6.4 Text object motions
-
- (
- [count] sentences backward (exclusive).
-
- )
- [count] sentences forward (exclusive).
-
- {
- [count] paragraphs backward (exclusive).
-
- }
- [count] paragraphs forward (exclusive).
-
- ]]
- [count] sections forward or to the next '{' in the
first column. When used after an operator, then the
'}' in the first column. (linewise).
-
- ][
- [count] sections forward or to the next '}' in the
first column (linewise).
-
- [[
- [count] sections backward or to the previous '{' in
the first column (linewise).
-
- []
- [count] sections backward or to the previous '}' in
the first column (linewise).
These commands move over three kinds of text objects.
A sentence is defined as ending at a '.', '!' or '?' followed by either the
end of a line, or by a space. {Vi: two spaces} Any number of closing ')',
']', '"' and ''' characters my appear after the '.', '!' or '?' before the
spaces or end of line. A paragraph and section boundary is also a sentence
boundary.
A paragraph begins after each empty line, and also at each of a set of
paragraph macros, specified by the pairs of characters in the 'paragraphs'
option. The default is "IPLPPPQPP LIpplpipbp", which corresponds to the
macros ".IP", ".LP", etc. (these are nroff macros, the dot must be in the
first column). A section boundary is also a paragraph boundary. Note that
this does not include a '{' or '}' in the first column.
A section begins after a form-feed in the first column and at each of a set
of section macros, specified by the pairs of characters in the 'sections'
option. The default is "SHNHH HUnhsh".
The "]" and "[" commands stop at the '{' or <}" in the first column. This is
useful to find the start or end of a function in a C program. Note that the
first character of the command determines the search direction and the
second character the type of brace found.
6.5 Text object selection
-
- a
- select [count] words (see word). {not in Vi}
-
- A
- select [count] WORDS (see WORD). {not in Vi}
-
- s
- select [count] sentences (see sentence). {not in Vi}
-
- p
- select [count] paragraphs (see paragraph). {not in
Vi}
-
- S
- select [count] blocks, from "[count] [(" to the
matching ')' (see [(). {not in Vi}
-
- P
- select [count] blocks, from "[count] [{" to the
matching '}' (see [{). {not in Vi}
These object selection commands can only be used in Visual mode and after an
operator.
When used after an operator:
- For non-block objects:
-
The operator applies to the object and the white space after the
object. If there is no white space after the object or when the
cursor was in the white space before the object, the white space
before the object is included.
- For a block object:
-
The operator applies to the block excluding the surrounding braces. If
the cursor was on one of the braces (or on the indent before '{' or
'}) they are included.
When used in Visual mode:
- When start and end of the Visual area are the same (just after typing "v"):
-
One object is selected, the same as for using an operator.
- When start and end of the Visual area are not the same:
-
For non-block objects the area is extended by one object or the white
space up to the next object. The direction in which this happens
depends on which side of the Visual area the cursor is. For the block
objects the block is extended one level outwards.
For illustration, here is a list of delete commands, grouped from small to big
objects. Note that for a single character and a whole line the existing vi
movement commands are used.
| "dl" |
delete character (alias: "x")
|
| "da" |
delete word
|
| "dA" |
delete WORD
|
| "dd" |
delete line
|
| "ds" |
delete sentence
|
| "dS" |
delete '(' ')' block
|
| "dp" |
delete paragraph
|
| "dP" |
delete '{' '}' block
|
Note the difference between using a movement command and an object. The
movement command operates from here (cursor position) to where the movement
takes us. When using an object the whole object is operated upon, no matter
where on the object the cursor is. For example, compare "dw" and "da": "dw"
deletes from the cursor position to the start of the next word, "da" deletes
the word under the cursor and the space after or before it.
6.6 Pattern searches
-
- /{pattern}[/]<CR>
- Search forward for the [count]'th occurrence of
{pattern} (exclusive).
- /{pattern}/{offset}<CR>
- Search forward for the [count]'th occurrence of
{pattern} and go {offset} lines up or down (see
below). (linewise).
-
- /<CR>
- Search forward for the [count]'th latest used
pattern with latest used {offset}.
- //{offset}<CR>
- Search forward for the [count]'th latest used
pattern with new {offset}. If {offset} is empty no
offset is used.
-
- ?{pattern}[?]<CR>
- Search backward for the [count]'th previous
occurrence of {pattern} (exclusive).
- ?{pattern}?{offset}<CR>
- Search backward for the [count]'th previous
occurrence of {pattern} and go {offset} lines up or
down (see below) (linewise).
-
- ?<CR>
- Search backward for the [count]'th latest used
pattern with latest used {offset}.
- ??{offset}<CR>
- Search backward for the [count]'th latest used
pattern with new {offset}. If {offset} is empty no
offset is used.
-
- n
- Repeat the latest "/" or "?" [count] times. {Vi: no
count}
-
- N
- Repeat the latest "/" or "?" [count] times in
opposite direction. {Vi: no count}
-
- *
- Search forward for the [count]'th occurrence of the
keyword after or under the cursor (exclusive). Only
whole keywords are search for, like with the command
"/\<keyword\>". If there is no keyword after or
under the cursor, any non-blank word is used to
search for. {not in Vi}
-
- #
- Same as "*", but search backward. The English pound
sign (character 163) also works. {not in Vi}
-
- g*
- Like "*", but don't put "\<" and "\>" around the word.
This makes the search also find matches that are not a
whole word. {not in Vi}
-
- g#
- Like "#", but don't put "\<" and "\>" around the word.
This makes the search also find matches that are not a
whole word. {not in Vi}
-
- gd
- Goto local Declaration. When the cursor is on a local
variable, this command will jump to its declaration.
First a search is made for the end of the previous
function, just like "[]". If it is not found the
search stops in line 1. From this position a search is
made for the keyword under the cursor, like with "*",
but lines that look like a comment are ignored (see
'comments' option). Note that this is not guaranteed
to work, Vim does not really check the syntax, it only
searches for a match with the keyword. If included
files also need to be searched use the commands listed
in include_search. {not in Vi}
-
- gD
- Goto global Declaration. When the cursor is on a
global variable that is defined in the file, this
command will jump to its declaration. This works just
like "gd", except that the search for the keyword
always starts in line 1. {not in Vi}
-
- CTRL-C
- Interrupt current (search) command.
While typing the search pattern the current match will be shown if the
'incsearch' option is on.
These commands search for the specified pattern. With "/" and "?" an
additional offset may be given. There are two types of offsets: line offsets
and character offsets. {the character offsets are not in Vi}
The offset gives the cursor position relative to the found match:
| [num] |
[num] lines downwards, in column 1
|
| +[num] |
[num] lines downwards, in column 1
|
| -[num] |
[num] lines upwards, in column 1
|
| e[+num] |
[num] characters to the right of the end of the match
|
| e[-num] |
[num] characters to the left of the end of the match
|
| s[+num] |
[num] characters to the right of the start of the match
|
| s[-num] |
[num] characters to the left of the start of the match
|
| b[+num] |
[num] characters to the right of the start (begin) of the match
|
| b[-num] |
[num] characters to the left of the start (begin) of the match
|
If a '-' or '+' is given but [num] is omitted, a count of one will be used.
When including an offset with 'e', the search becomes inclusive (the
character the cursor lands on is included in operations).
Examples:
| pattern |
cursor position
|
| /test/+1 |
one line below "test", in column 1
|
| /test/e |
on the last t of "test"
|
| /test/s+2 |
on the 's' of "test"
|
| /test/b-3 |
three characters before "test"
|
If one of these commands is used after an operator, the characters between
the cursor position before and after the search is affected. However, if a
line offset is given, the whole lines between the two cursor positions are
affected.
A very special offset is ';' followed by another search command. For example:
/test 1/;/test
/test.*/+1;?ing?
The first one first finds the next occurence of "test 1", and then the first
occurence of "test" after that.
This is like executing two search commands after each other, except that:
- It can be used as a single motion command after an operator.
- The direction for a following "n" or "N" command comes from the first
search command.
- When an error occurs the cursor is not moved at all.
The last used <pattern> and <offset> are remembered. They can be used to
repeat the search, possibly in another direction or with another count. Note
that two patterns are remembered: one for 'normal' search commands and one
for the substitute command ":s". Each time an empty <pattern> is given, the
previously used <pattern> is used.
In Vi the ":tag" command sets the last search pattern when the tag is searched
for. In Vim this is not done, the previous search pattern is still remembered,
unless the 't' flag is present in 'cpoptions'. The search pattern is always
put in the search history.
If the 'wrapscan' option is set (which is the default), searches wrap around
the end of the buffer. If 'wrapscan' is not set, the backward search stops
at the beginning and the forward search stops at the end of the buffer. If
'wrapscan' is set and the pattern was not found the error message "pattern
not found" is given, and the cursor will not be moved. If 'wrapscan' is not
set the message becomes "search hit BOTTOM without match" when searching
forward, or "search hit TOP without match" when searching backward. If
wrapscan is set and the search wraps around the end of the file the message
"search hit TOP, continuing at BOTTOM" or "search hit BOTTOM, continuing at
TOP" is given when searching backwards or forwards respectively. This can be
switched off by setting the 's' flag in the 'shortmess' option. The highlight
method 'w' is used for this message (default: standout).
The "*" and "#" commands search for the keyword currently under the cursor.
If there is no keyword under the cursor, the first one to the right is used.
This keyword may only contain letters and characters in 'iskeyword'. Note
that if you type with ten fingers, the characters are easy to remember: the
"#" is under your left hand middle finger (search to the left and up) and
the "*" is under your right hand middle finger (search to the right and
down). If there is no keyword under or after the cursor, a search is done
for any word under or after the cursor. Blanks (<Tab>s and/or <Space>s) are
then recognized as delimiters for the word.
The definition of a pattern:
Patterns may contain special characters, depending on the setting of the
'magic' option.
- A pattern is one or more branches, separated by "\|". It matches anything
that matches one of the branches. Example: "foo\|bar" matches "foo" and
"bar".
- A branch is one or more pieces, concatenated. It matches a match for the
first, followed by a match for the second, etc. Example: "foo[0-9]bar",
first match "foo", then a digit and then "bar".
- A piece is an atom, possibly followed by:
| 'magic' option |
'nomagic' option
|
| * |
\* |
matches 0 or more of the preceding atom
|
| \+ |
\+ |
matches 1 or more of the preceding atom {not in Vi}
|
| \= |
\= |
matches 0 or 1 of the preceding atom {not in Vi}
|
| Examples:
|
| .* |
.\* |
matches anything, also empty string
|
| ^.\+$ |
^.\+$ |
matches any non-empty line
|
| foo\= |
foo\= |
matches "fo" and "foo"
|
- An atom can be:
- One of these five:
| magic |
nomagic
|
| ^ |
^ |
at beginning of pattern, matches start of
line
|
| $ |
$ |
at end of pattern or in front of "\|",
matches end of line
|
| . |
\. |
matches any single character
|
| \< |
\< |
matches the beginning of a word
|
| \> |
\> |
matches the end of a word
|
| \i |
\i |
matches any identifier character (see
'isident' option) {not in Vi}
|
| \I |
\I |
like "\i", but excluding digits {not in Vi}
|
| \k |
\k |
matches any keyword character (see
'iskeyword' option) {not in Vi}
|
| \K |
\K |
like "\k", but excluding digits {not in Vi}
|
| \f |
\f |
matches any file name character (see
'isfname' option) {not in Vi}
|
| \F |
\F |
like "\f", but excluding digits {not in Vi}
|
| \p |
\p |
matches any printable character (see
'isprint' option) {not in Vi}
|
| \P |
\P |
like "\p", but excluding digits {not in Vi}
|
| \e |
\e |
<Esc>
|
| \t |
\t |
<Tab>
|
| \r |
\r |
<CR>
|
| \b |
\b |
<BS>
|
| ~ |
\~ |
matches the last given substitute pattern
|
| \(\) |
\(\) |
A pattern enclosed by escaped parentheses
(e.g. "\(^a\)") matches that pattern
|
| x |
x |
A single character, with no special meaning,
matches itself
|
| \x |
\x |
A backslash followed by a single character,
with no special meaning, matches the single
character
|
| [] |
\[] |
A range. This is a sequence of characters
enclosed in "[]" or "\[]". It matches any
single character from the sequence. If the
sequence begins with "^", it matches any
single character NOT in the sequence. If two
characters in the sequence are separated by
'-', this is shorthand for the full list of
ASCII characters between them. E.g. "[0-9]"
matches any decimal digit. To include a
literal "]" in the sequence, make it the
first character (following a possible "^").
E.g. "[]xyz]" or "[^]xyz]". To include a
literal '-', make it the first or last
character.
|
If the 'ignorecase' option is set, the case of letters is ignored.
It is impossible to have a pattern that contains a line break.
Examples:
- ^beep(
- Probably the start of the C function "beep".
- [a-zA-Z]$
- Any alphabetic character at the end of a line.
- \<\I\i or
- \(^\|[^a-zA-Z0-9_]\)[a-zA-Z_]\+[a-zA-Z0-9_]*
-
A C identifier (will stop in front of it).
- \(\.$\|\. \)
- A period followed by end-of-line or a space.
Note that "\(\. \|\.$\)" does not do the same,
because '$' is not end-of-line in front of '\)'.
This was done to remain Vi-compatible.
- [.!?][])"']*\($\|[ ]\)
- A search pattern that finds the end of a sentence,
with almost the same definition as the ")" command.
- Technical detail:
-
<Nul> characters in the file are stored as <NL> in memory. In the display
they are shown as "^@". The translation is done when reading and writing
files. To match a <Nul> with a search pattern you can just enter CTRL-@ or
"CTRL-V 000". This is probably just what you expect. Internally the
character is replaced with a <NL> in the search pattern. What is unusual is
that typing CTRL-V CTRL-J also inserts a <NL>, thus also searches for a
<Nul> in the file. {Vi cannot handle <Nul> characters in the file at all}
6.7 Various motions
-
- m<a-zA-Z>
- Set mark <a-zA-Z> at cursor position (does not move
the cursor, this is not a motion command).
-
- :[range]ma[rk] <a-zA-Z>
- Set mark <a-zA-Z> at last line number in [range],
column 0. Default is cursor line.
-
- :[range]k<a-zA-Z>
- Same as :mark, but the space before the mark name can
be omitted.
-
- '<a-z>
- To the first non-blank character on the line with
mark <a-z> (linewise).
-
- '<A-Z0-9>
- To the first non-blank character on the line with
mark <A-Z0-9> in the correct file (linewise when in
same file, not a motion command when in other file).
{not in Vi}
-
- `<a-z>
- To the mark <a-z> (exclusive).
-
- `<A-Z0-9>
- To the mark <A-Z0-9> in the correct file (exclusive
when in same file, not a motion command when in
other file). {not in Vi}
-
- :marks
- List all the current marks (not a motion command).
{not in Vi}
- :marks {arg}
- List the marks that are mentioned in {arg} (not a
motion command). For example:
:marks aB
to list marks 'a' and 'B'. {not in Vi}
A mark is not visible in any way. It is just a position in the file that is
remembered. Do not confuse marks with named registers, they are totally
unrelated.
| 'a - 'z |
lowercase marks, valid within one file
|
| 'A - 'Z |
uppercase marks, also called file marks, valid between files
|
| '0 - '9 |
numbered marks, set from .viminfo file
|
Lowercase marks 'a to 'z are remembered as long as the file remains in the
buffer list. If you remove the file from the buffer list, change a character
in a line or delete a line that contains a mark, that mark is erased.
Lowercase marks can be used in combination with operators. For example: "d't"
deletes the lines from the cursor position to mark 't'. Hint: Use mark 't' for
Top, 'b' for Bottom, etc.. Lowercase marks are restored when using undo and
redo.
Uppercase marks 'A to 'Z include the file name. {Vi: no uppercase marks} You
can use them to jump from file to file. You can only use an uppercase mark
with an operator if the mark is in the current file. The line number of the
mark remains correct, even if you insert/delete lines or edit another file for
a moment. When the 'viminfo' option is not empty, uppercase marks are kept in
the .viminfo file. See viminfo_file_marks.
Numbered marks '0 to '9 are quite different. They can not be set directly.
They are only present when using a viminfo_file. Basically '0
is the location of the cursor when you last exited Vim, '1 the last but one
time, etc. See viminfo_file_marks.
-
- '[
- To the first non-blank character on the first line
of the previously operated, inserted or putted text.
{not in Vi}
-
- `[
- To the first character of the previously operated,
inserted or putted text. {not in Vi}
-
- ']
- To the first non-blank character on the last line of
the previously operated, inserted or putted text.
{not in Vi}
-
- `]
- To the last character of the previously operated,
inserted or putted text. {not in Vi}
After executing an operator the Cursor is put at the beginning of the text
that was operated upon. After a put command ("p" or "P") the cursor is
sometimes placed at the first inserted line and sometimes on the last inserted
character. The four commands above put the cursor at either end. Example:
After yanking 10 lines you want to go to the last one of them: "10Y']". After
inserting several lines with the "p" command you want to jump to the lowest
inserted line: "p']". This also works for text that has been inserted.
Note: After deleting text, the start and end positions are the same, except
when using blockwise Visual mode. These commands do not work when no
operator or put command has been used yet in the current file.
-
- '<
- To the first non-blank character on the first line
of the last selected Visual area. {not in Vi}.
-
- `<
- To the first character of the last selected Visual
area. {not in Vi}.
-
- '>
- To the first non-blank character on the last line
of the last selected Visual area. {not in Vi}.
-
- `>
- To the last character of the last selected Visual
area. {not in Vi}.
-
- ''
- To the first non-blank character of the line where
the cursor was before the latest jump (linewise).
-
- ``
- To the position before latest jump (exclusive).
-
- '"
- To the first non-blank character of the line where
the cursor was the last time the current buffer was
exited (linewise). {not in Vi}.
-
- `"
- To the cursor position when last exiting the current
buffer (exclusive). {not in Vi}.
A "jump" is one of the following commands: "'", "`", "G", "/", "?", "n",
"N", "%", "(", ")", "[[", "]]", "{", "}", ":s", ":tag", "L", "M", "H" and
the commands that start editing a new file. If you make the cursor "jump"
with one of these commands, the position of the cursor before the jump is
remembered. You can return to that position with the "''" and "``" command,
unless the line containing that position was changed or deleted.
-
- CTRL-O
- Go to [count] Older cursor position in jump list
(not a motion command). {not in Vi}
- <Tab> or
-
- CTRL-I
- Go to [count] newer cursor position in jump list
(not a motion command). {not in Vi}
-
- :ju[mps]
- Print the jump list (not a motion command). {not in
Vi}
Jumps are remembered in a jump list. With the CTRL-O and CTRL-I command you
can go to cursor positions before older jumps, and back again. Thus you can
move up and down the list.
For example, after three jump commands you have this jump list:
| jump |
line |
file
|
| 1 |
1 |
-current-
|
| 2 |
70 |
-current-
|
| 3 |
1154 |
-current-
|
| >
|
You are currently in line 1167. If you then use the CTRL-O command, the
cursor is put in line 1154. This results in:
| jump |
line |
file
|
| 1 |
1 |
-current-
|
| 2 |
70 |
-current-
|
| > 3 |
1154 |
-current-
|
| 4 |
1167 |
-current-
|
The pointer will be set at the last used jump position. The next CTRL-O
command will use the entry above it, the next CTRL-I command will use the
entry below it. If the pointer is below the last entry, this indicates that
you did not use a CTRL-I or CTRL-O before. In this case the CTRL-O command
will cause the cursor position to be added to the jump list, so you can get
back to the position before the CTRL-O. In this case this is line 1167.
With more CTRL-O commands you will go to lines 70 and 1. If you use CTRL-I
you can go back to 1154 and 1167 again.
If you use a jump command, the current line number is inserted at the end of
the jump list. If the same line was already in the jump list, it is removed.
The result is that when repeating CTRL-O you will get back to old positions
only once.
After the CTRL-O command that got you into line 1154 you could give another
jump command (e.g. "G"). The jump list would then become:
| jump |
line |
file
|
| 1 |
1 |
-current-
|
| 2 |
70 |
-current-
|
| 3 |
1167 |
-current-
|
| 4 |
1154 |
-current-
|
| >
|
The line numbers will be adjusted for deleted and inserted lines. This fails
if you stop editing a file without writing, like with ":n!".
-
- %
- Find the next item in this line after or under the
cursor and jump to its match (inclusive). Items can
be:
| ([{}]) |
parenthesis or (curly/square) brackets
|
| /* */ |
start or end of C-style comment
|
| #if, #ifdef, #else, #elif, #endif |
C preprocessor conditionals
|
Parens and braces preceded with a backslash are
ignored. When the '%' character is not present in
'cpoptions', parens and braces inside quotes are
ignored, unless the number of parens/braces in a line
is uneven and this line and the previous one does not
end in a backslash. No count is allowed ({count}%
jumps to a line {count} percentage down the file).
Using '%' on #if/#else/#endif makes the movement
linewise.
-
- [(
- go to [count] previous unmatched '('. {not in Vi}
-
- [{
- go to [count] previous unmatched '{'. {not in Vi}
-
- ])
- go to [count] next unmatched ')'. {not in Vi}
-
- ]}
- go to [count] next unmatched '}'. {not in Vi}
The above four commands can be used to go to the start or end of the current
code block. It is like doing "%" on the '(', ')', '{' or '}' at the other
end of the code block, but you can do this from anywhere in the code block.
Very useful for C programs. Example: When standing on "case x:", "[{" will
bring you back to the switch statement.
-
- [#
- go to [count] previous unmatched "#if" or "#else".
{not in Vi}
-
- ]#
- go to [count] next unmatched "#else" or "#endif". {not
in Vi}
These two commands work in C programs that contain #if/#else/#endif
constructs. It brings you to the start or end of the #if/#else/#endif where
the current line is included. You can then use "%" to go to the matching line.
-
- [* or [/
- go to [count] previous start of a C comment "/*". {not
in Vi}
-
- ]* or ]/
- go to [count] next end of a C comment "*/". {not
in Vi}
-
- H
- To line [count] from top (Home) of screen (default:
first line on the screen) on the first non-blank
character (linewise). See also 'startofline' option.
-
- M
- To Middle line of screen, on the first non-blank
character (linewise). See also 'startofline' option.
-
- L
- To line [count] from bottom of screen (default: Last
line on the screen) on the first non-blank character
(linewise). See also 'startofline' option.
- <LeftMouse>
- Moves to the position on the screen where the mouse
click is (inclusive). See also <LeftMouse>. If the
position is in a status line, that window is made the
active window and the cursor is not moved. {not in Vi}
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
|