Motion
Nvim:help pages,generated fromsource using thetree-sitter-vimdoc parser.
These commands move the cursor position. If the new position is off of thescreen, the screen is scrolled to show the cursor (see also
'scrolljump' and
'scrolloff' options).
General remarks:
If you want to know where you are in the file use the "CTRL-G" command
CTRL-G or the "g
CTRL-G" command
g_CTRL-G. If you set the
'ruler' option,the cursor position is continuously shown in the status line (which slows downVim a little).
Experienced users prefer the hjkl keys because they are always right undertheir fingers. Beginners often prefer the arrow keys, because they do notknow what the hjkl keys do. The mnemonic value of hjkl is clear from lookingat the keyboard. Think of j as an arrow pointing downwards.
The
'virtualedit' option can be set to make it possible to move the cursor topositions where there is no character or within a multi-column character (likea tab).
The motion commands can be used after an operator command, to have the commandoperate on the text that was moved over. That is the text between the cursorposition before and after the motion. Operators are generally used to deleteor change text. The following operators are available:
c cchange
d ddelete
y yyank into register (does not change the text)
~ ~swap case (only if
'tildeop' is set)
g~ g~swap case
gu gumake lowercase
gU gUmake uppercase
! !filter through an external program
= =filter through
'equalprg' or C-indenting if empty
gq gqtext formatting
gw gwtext formatting with no cursor movement
g? g?ROT13 encoding
> >shift right
< <shift left
zf zfdefine a fold
g@ g@call function set with the
'operatorfunc' option
motion-count-multipliedIf the motion includes a count and the operator also had a count before it,the two counts are multiplied. For example: "2d3w" deletes six words.
operator-doubledWhen doubling the operator it operates on a line. When using a count, beforeor after the first character, that many lines are operated upon. Thus
3dddeletes three lines. A count before and after the first character ismultiplied, thus
2y3y yanks six lines.
operator-resulting-posAfter applying the operator the cursor is mostly left at the start of the textthat was operated upon. For example, "yfe" doesn't move the cursor, but "yFe"moves the cursor leftwards to the "e" where the yank started.The
'startofline' option applies only to the "d", "<<", "==" and ">>" linewiseoperations.
linewisecharwisecharacterwiseThe operator either affects whole lines, or the characters between the startand end position. Generally, motions that move between lines affect lines(are linewise), and motions that move within a line affect characters (arecharwise). However, there are some exceptions.
exclusiveinclusiveCharacter motion is either inclusive or exclusive. When inclusive, thestart and end position of the motion are included in the operation. Whenexclusive, the last character towards the end of the buffer is not included.Linewise motions always include the start and end position. Plugins cancheck the v:event.inclusive flag of the
TextYankPost event.
Which motions are linewise, inclusive or exclusive is mentioned with thecommand. There are however, two general exceptions:1. 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: "}" moves to the first line after a paragraph, but "d}" will not include that line.
exclusive-linewise2. 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.
Note that when the operator is pending (the operator command is typed, but themotion isn't yet), a special set of mappings can be used. See
:omap.
Instead of first giving the operator and then a motion you can use Visualmode: mark the start of the text with "v", move the cursor to the end of thetext that is to be affected and then hit the operator. The text between thestart and the cursor position is highlighted, so you can see what text willbe operated upon. This allows much more freedom, but requires more keystrokes and has limited redo functionality. See the chapter on Visual mode
Visual-mode.
You can use a ":" command for a motion. For example "d:call FindEnd()".But this can't be repeated with "." if the command is more than one line.This can be repeated:
d:call search("f")<CR>This cannot be repeated:
d:if 1<CR> call search("f")<CR>endif<CR>Note that when using ":" any motion becomes charwise exclusive.
inclusive-motion-selection-exclusiveWhen
'selection' is "exclusive",
Visual mode is active and an inclusivemotion has been used, the cursor position will be adjusted by anothercharacter to the right, so that the Visual selection includes the expectedtext and can be acted upon.
forced-motionFORCING A MOTION TO BE LINEWISE, CHARWISE OR BLOCKWISE
When a motion is not of the type you would like to use, you can force anothertype by using "v", "V" or
CTRL-V just after the operator.Example:
dj
deletes two lines
dvj
deletes from the cursor position until the character below the cursor
d<C-V>j
deletes the character under the cursor and the character below the cursor.Be careful with forcing a linewise movement to be used charwise or blockwise,the column may not always be defined.
o_vvWhen used after an operator, before the motion command: Forcethe operator to work charwise, also when the motion islinewise. If the motion was linewise, it will become
exclusive.If the motion already was charwise, toggleinclusive/exclusive. This can be used to make an exclusivemotion inclusive and an inclusive motion exclusive.
o_VVWhen used after an operator, before the motion command: Forcethe operator to work linewise, also when the motion ischarwise.
o_CTRL-VCTRL-VWhen used after an operator, before the motion command: Forcethe operator to work blockwise. This works like Visual blockmode selection, with the corners defined by the cursorposition before and after the motion.
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 "$", whichmay move to one of the next lines. See
'whichwrap' option to make some of thecommands move across line boundaries.
hor
h<Left>or
<Left>CTRL-Hor
CTRL-H<BS><BS>[count] characters to the left.
exclusive motion.
Note: If you prefer
<BS> to delete a character, usethe mapping:
:map CTRL-V<BS>X
(to enter "CTRL-V<BS>" type theCTRL-V key, followedby the<BS> key)
00To the first character of the line.
exclusivemotion.
<Home><kHome><Home>To the first character of the line.
exclusivemotion. When moving up or down next, stay in sameTEXT column (if possible). Most other commands stayin the same SCREEN column.
<Home> works like "1|",which differs from "0" when the line starts with a
<Tab>.
^^To the first non-blank character of the line.
exclusive motion. Any count is ignored.
$<End><kEnd>$ or
<End>To the end of the line. When a count is given also go[count - 1] lines downward, or as far is possible.
inclusive motion. If a count of 2 or larger isgiven and the cursor is on the last line, that is anerror and the cursor doesn't move.In Visual mode the cursor goes to just after the lastcharacter in the line.When
'virtualedit' is active, "$" may move the cursorback from past the end of the line to the lastcharacter in the line.
g_g_To the last non-blank character of the line and[count - 1] lines downward
inclusive.
g0g<Home>g0 or g<Home>When lines wrap (
'wrap' on): To the first character ofthe screen line.
exclusive motion. Differs from"0" when a line is wider than the screen.When lines don't wrap (
'wrap' off): To the leftmostcharacter of the current line that is on the screen.Differs from "0" when the first character of the lineis not on the screen.
g^g^When lines wrap (
'wrap' on): To the first non-blankcharacter of the screen line.
exclusive motion.Differs from "^" when a line is wider than the screen.When lines don't wrap (
'wrap' off): To the leftmostnon-blank character of the current line that is on thescreen. Differs from "^" when the first non-blankcharacter of the line is not on the screen.
gmgmLike "g0", but half a screenwidth to the right (or asmuch as possible).
gMgMLike "g0", but to halfway the text of the line.With a count: to this percentage of text in the line.Thus "10gM" is near the start of the text and "90gM"is near the end of the text.
g$g$When lines wrap (
'wrap' on): To the last character ofthe screen line and [count - 1] screen lines downward
inclusive. Differs from "$" when a line is widerthan the screen.When lines don't wrap (
'wrap' off): To the rightmostcharacter of the current line that is visible on thescreen. Differs from "$" when the last character ofthe line is not on the screen or when a count is used.Additionally, vertical movements keep the column,instead of going to the end of the line.When
'virtualedit' is enabled moves to the end of thescreen line.
g<End>g<kEnd>g<End>Like
g$ but to the last non-blank characterinstead of the last character.
bar|To screen column [count] in the current line.
exclusive motion. Ceci n'est pas une pipe.
ff{char}To [count]'th occurrence of
{char} to the right. Thecursor is placed on
{char}inclusive.
{char} can be entered as a digraph
digraph-arg.When
'encoding' is set to Unicode, composingcharacters may be used, see
utf-8-char-arg.
:lmap mappings apply to
{char}. The
CTRL-^ commandin Insert mode can be used to switch this on/off
i_CTRL-^.
FF{char}To the [count]'th occurrence of
{char} to the left.The cursor is placed on
{char}exclusive.
{char} can be entered like with the
f command.
tt{char}Till before [count]'th occurrence of
{char} to theright. The cursor is placed on the character left of
{char}inclusive.
{char} can be entered like with the
f command.
TT{char}Till after [count]'th occurrence of
{char} to theleft. The cursor is placed on the character right of
{char}exclusive.
{char} can be entered like with the
f command.
;;Repeat latest f, t, F or T [count] times. See
cpo-; ,,Repeat latest f, t, F or T in opposite direction[count] times. See also
cpo-; gkor
gkg<Up>g<Up>[count] display lines upward.
exclusive motion.Differs from 'k' when lines wrap, and when used withan operator, because it's not linewise.
gjor
gjg<Down>g<Down>[count] display lines downward.
exclusive motion.Differs from 'j' when lines wrap, and when used withan operator, because it's not linewise.
--<minus>[count] lines upward, on the first non-blankcharacter
linewise.
__
<underscore>[count] - 1 lines downward, on the first non-blankcharacter
linewise.
<C-End><C-End>Goto line [count], default last line, on the lastcharacter
inclusive.
:[range]:[range]Set the cursor on the last line number in [range].In Ex mode, print the lines in [range].[range] can also be just one line number, e.g., ":1"or ":'m".In contrast with
G this command does not modify the
jumplist.
N%{count}%Go to
{count} percentage in the file, on the firstnon-blank in the line
linewise. To compute the newline number this formula is used: (
{count} * number-of-lines + 99) / 100See also
'startofline' option.
:[range]go[to] [count]
:go:gotogo[count]goGo to [count] byte in the buffer.
exclusive motion.Default [count] is one, start of the file. Whengiving [range], the last number in it used as the bytecount. End-of-line characters are counted dependingon the current
'fileformat' setting.Also see the
line2byte() function, and the 'o'option in
'statusline'.
These commands move to the specified line. They stop when reaching the firstor 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 lastcharacter of the line.
eeForward to the end of word [count]
inclusive.Does not stop in an empty line.
EEForward to the end of WORD [count]
inclusive.Does not stop in an empty line.
These commands move over words or WORDS.
wordA word consists of a sequence of letters, digits and underscores, or asequence of other non-blank characters, separated with white space (spaces,tabs,
<EOL>). This can be changed with the
'iskeyword' option. An empty lineis also considered to be a word.
WORDA WORD consists of a sequence of non-blank characters, separated with whitespace. An empty line is also considered to be a WORD.
A sequence of folded lines is counted for one word of a single character."w" and "W", "e" and "E" move to the start/end of the first word or WORD aftera range of folded lines. "b" and "B" move to the start of the first word orWORD before the fold.
Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor ison a non-blank. This is Vi-compatible, see
cpo-_ to change the behavior.
Another special case: When using the "w" motion in combination with anoperator and the last word moved over is at the end of a line, the end ofthat word becomes the end of the operated text, not the first word in thenext line.
The original Vi implementation of "e" is buggy. For example, the "e" commandwill 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 thesame, which is more logical. However, this causes a small incompatibilitybetween Vi and Vim.
]]]][count]
sections forward or to the next "{" in thefirst column. When used after an operator, then alsostops below a "}" in the first column.
exclusiveNote that
exclusive-linewise often applies.In a :terminal buffer each shell prompt is treated asa section.
terminal_]] These commands move over three kinds of text objects.
sentenceA sentence is defined as ending at a '.', '!' or '?' followed by either theend of a line, or by a space or tab. Any number of closing ')', ']', '"'and ''' characters may appear after the '.', '!' or '?' before the spaces,tabs or end of line. A paragraph and section boundary is also a sentenceboundary.If the 'J' flag is present in
'cpoptions', at least two spaces have tofollow the punctuation mark;
<Tab>s are not recognized as white space.The definition of a sentence cannot be changed.
paragraphA paragraph begins after each empty line, and also at each of a set ofparagraph macros, specified by the pairs of characters in the
'paragraphs'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds tothe macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be inthe first column). A section boundary is also a paragraph boundary.Note that a blank line (only containing white space) is NOT a paragraphboundary.
Note: this does not include a '{' or '}' in the first column.
sectionA section begins after a form-feed (
<C-L>) in the first column and at each ofa set of section macros, specified by the pairs of characters in the
'sections' option. The default is "SHNHH HUnhsh", which defines a section tostart at the nroff macros ".SH", ".NH", ".H", ".HU", ".nh" and ".sh".In a :terminal buffer each shell prompt is treated as a section.
terminal_]] The "]]" and "[[" commands stop at the '{' in the first column. This isuseful to find the start of a function in a C program. To search for a '}' inthe first column, the end of a C function, use "][" (forward) or "[]"(backward). Note that the first character of the command determines thesearch direction.
If your '{' or '}' are not in the first column, and you would like to use "[["and "]]" anyway, try these mappings:
:map [[ ?{<CR>w99[{:map ][ /}<CR>b99]}:map ]] j0[[%/{<CR>:map [] k$][%?}<CR>[type these literally, see
<>]
This is a series of commands that can only be used while in Visual mode orafter an operator. The commands that start with "a" select "a"n objectincluding white space, the commands starting with "i" select an "inner" objectwithout white space, or just the white space. Thus the "inner" commandsalways select less text than the "a" commands.
Also seegn andgN, operating on the last search pattern.
v_awawaw"a word", select [count] words (see
word).Leading or trailing white space is included, but notcounted.When used in Visual linewise mode "aw" switches toVisual charwise mode.
v_iwiwiw"inner word", select [count] words (see
word).White space between words is counted too.When used in Visual linewise mode "iw" switches toVisual charwise mode.
v_aWaWaW"a WORD", select [count] WORDs (see
WORD).Leading or trailing white space is included, but notcounted.When used in Visual linewise mode "aW" switches toVisual charwise mode.
v_iWiWiW"inner WORD", select [count] WORDs (see
WORD).White space between words is counted too.When used in Visual linewise mode "iW" switches toVisual charwise mode.
v_asasas"a sentence", select [count] sentences (see
sentence).When used in Visual mode it is made charwise.
v_isisis"inner sentence", select [count] sentences (see
sentence).When used in Visual mode it is made charwise.
v_apapap"a paragraph", select [count] paragraphs (see
paragraph).Exception: a blank line (only containing white space)is also a paragraph boundary.When used in Visual mode it is made linewise.
v_ipipip"inner paragraph", select [count] paragraphs (see
paragraph).Exception: a blank line (only containing white space)is also a paragraph boundary.When used in Visual mode it is made linewise.
a]
v_a]v_a[a]a[a["a [] block", select [count] '[' ']' blocks. Thisgoes backwards to the [count] unclosed '[', and findsthe matching ']'. The enclosed text is selected,including the '[' and ']'. The
cpo-M option flagis used to handle escaped brackets.When used in Visual mode it is made charwise.
i]
v_i]v_i[i]i[i["inner [] block", select [count] '[' ']' blocks. Thisgoes backwards to the [count] unclosed '[', and findsthe matching ']'. The enclosed text is selected,excluding the '[' and ']'. It's an error to select anempty inner block like "[]". The
cpo-M option flagis used to handle escaped brackets.When used in Visual mode it is made charwise.
a)
v_a)a)a(a(
vabv_abv_a(abab"a block", select [count] blocks, from "[count] [(" tothe matching ')', including the '(' and ')' (see
[(). Does not include white space outside of theparenthesis. The
cpo-M option flag is used tohandle escaped parenthesis.When used in Visual mode it is made charwise.
i)
v_i)i)i(i(
vibv_ibv_i(ibib"inner block", select [count] blocks, from "[count] [("to the matching ')', excluding the '(' and ')' (see
[(). If the cursor is not inside a () block, thenfind the next "(". It's an error to select an emptyinner block like "()". The
cpo-M option flagis used to handle escaped parenthesis.When used in Visual mode it is made charwise.
a>
v_a>v_a<a>a<a<"a <> block", select [count] <> blocks, from the[count]'th unmatched '<' backwards to the matching'>', including the '<' and '>'. The
cpo-M option flagis used to handle escaped '<' and '>'.When used in Visual mode it is made charwise.
i>
v_i>v_i<i>i<i<"inner <> block", select [count] <> blocks, fromthe [count]'th unmatched '<' backwards to the matching'>', excluding the '<' and '>'. It's an error toselect an empty inner block like "<>". The
cpo-Moption flag is used to handle escaped '<' and '>'.When used in Visual mode it is made charwise.
v_atatat"a tag block", select [count] tag blocks, from the[count]'th unmatched "<aaa>" backwards to the matching"</aaa>", including the "<aaa>" and "</aaa>".See
tag-blocks about the details.When used in Visual mode it is made charwise.
v_ititit"inner tag block", select [count] tag blocks, from the[count]'th unmatched "<aaa>" backwards to the matching"</aaa>", excluding the "<aaa>" and "</aaa>".See
tag-blocks about the details.When used in Visual mode it is made charwise.
a}
v_a}a}a{a{
v_aBv_a{aBaB"a Block", select [count] Blocks, from
[count] [{ tothe matching "}", including the "{" and "}" (see
[{). The
cpo-M option flag is used to handleescaped braces.When used in Visual mode it is made charwise.
i}
v_i}i}i{i{
v_iBv_i{iBiB"inner Block", select [count] Blocks, from
[count] [{to the matching "}", excluding the "{" and "}" (see
[{). It"s an error to select an empty inner blocklike "{}". The
cpo-M option flag is used to handleescaped braces.When used in Visual mode it is made charwise.
a"
v_aquoteaquotea'
v_a'a'a`
v_a`a`"a quoted string". Selects the text from the previousquote until the next quote. The
'quoteescape' optionis used to skip escaped quotes.Only works within one line.When the cursor starts on a quote, Vim will figure outwhich quote pairs form a string by searching from thestart of the line.Any trailing white space is included, unless there isnone, then leading white space is included.When used in Visual mode it is made charwise.Repeating this object in Visual mode another string isincluded. A count is currently not used.
i"
v_iquoteiquotei'
v_i'i'i`
v_i`i`Like a", a' and a`, but exclude the quotes andrepeating won't extend the Visual selection.Special case: With a count of 2 the quotes areincluded, but no extra white space as with a"/a'/a`.
o_object-selectWhen used after an operator:For non-block objects:For the "a" commands: The operator applies to the object and the whitespace after the object. If there is no white space after the objector when the cursor was in the white space before the object, the whitespace before the object is included.For the "inner" commands: If the cursor was on the object, theoperator applies to the object. If the cursor was on white space, theoperator applies to the white space.For a block object:The operator applies to the block where the cursor is in, or the blockon which the cursor is on one of the braces. For the "inner" commandsthe surrounding braces are excluded. For the "a" commands, the bracesare included.
v_object-selectWhen 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 whitespace up to the next object, or both for the "a" objects. Thedirection in which this happens depends on which side of the Visualarea the cursor is. For the block objects the block is extended onelevel outwards.
For illustration, here is a list of delete commands, grouped from small to bigobjects. Note that for a single character and a whole line the existing vimovement commands are used."dl"delete character (alias: "x")
dl "diw"delete inner word
diw"daw"delete a word
daw"diW"delete inner WORD (see
WORD)
diW"daW"delete a WORD (see
WORD)
daW"dgn" delete the next search pattern match
dgn"dd"delete one line
dd "dis"delete inner sentence
dis"das"delete a sentence
das"dib"delete inner '(' ')' block
dib"dab"delete a '(' ')' block
dab"dip"delete inner paragraph
dip"dap"delete a paragraph
dap"diB"delete inner '{' '}' block
diB"daB"delete a '{' '}' block
daBNote the difference between using a movement command and an object. Themovement command operates from here (cursor position) to where the movementtakes us. When using an object the whole object is operated upon, no matterwhere on the object the cursor is. For example, compare "dw" and "daw": "dw"deletes from the cursor position to the start of the next word, "daw" deletesthe word under the cursor and the space after or before it.
For the "it" and "at" text objects an attempt is done to select blocks betweenmatching tags for HTML and XML. But since these are not completely compatiblethere are a few restrictions.
The normal method is to select a<tag> until the matching </tag>. For "at"the tags are included, for "it" they are excluded. But when "it" is repeatedthe tags will be included (otherwise nothing would change). Also, "it" usedon a tag block with no contents will select the leading tag.
"<aaa/>" items are skipped. Case is ignored, also for XML where case doesmatter.
In HTML it is possible to have a tag like<br> or <meta ...> without amatching end tag. These are ignored.
The text objects are tolerant about mistakes. Stray end tags are ignored.
Jumping to a mark can be done in two ways:1. With (backtick): The cursor is positioned at the specified location and the motion is
exclusive.2. With ' (single quote): The cursor is positioned on the first non-blank character in the line of the specified location and the motion is linewise.
mark-view3. Apart from the above if
'jumpoptions' contains "view", they will also try torestore the mark view. This is the number of lines between the cursor positionand the window topline (first buffer line displayed in the window) when it wasset.
mmarkMarkm{a-zA-Z}Set mark
{a-zA-Z} at cursor position (does not movethe cursor, this is not a motion command).
m'm`m' or m`Set the previous context mark. This can be jumped towith the "''" or "``" command (does not move thecursor, this is not a motion command).
m[m]m[ or m]Set the
'[ or
'] mark. Useful when an operator isto be simulated by multiple commands. (does not movethe cursor, this is not a motion command).
m<m>m< or m>Set the
'< or
'> mark. Useful to change what the
gv command selects. (does not move the cursor, thisis not a motion command).Note that the Visual mode cannot be set, only thestart and end position.
:ma:markE191:[range]ma[rk]
{a-zA-Z'}Set mark
{a-zA-Z'} at last line number in [range],column 0. Default is cursor line.
:k:[range]k{a-zA-Z'}Same as :mark, but the space before the mark name canbe omitted.
''a``a'{a-z}{a-z}Jump to the mark {a-z} in the current buffer.
'A'0`A`0'
{A-Z0-9}{A-Z0-9}To the mark {A-Z0-9} in the file where it was set (nota motion command when in another file).
g'g'ag`g`ag'{mark} g`{mark}Jump to the
{mark}, but don't change the jumplist whenjumping within the current buffer. Example:
g`"
jumps to the last known position in a file.See also
:keepjumps.
:marks:marksList all the current marks (not a motion command).The
'(,
'),
'{ and
'} marks are not listed.The first column has number zero.
E283:marks
{arg}List the marks that are mentioned in
{arg} (not amotion command). For example:
:marks aB
to list marks 'a' and 'B'.
:delm:delmarks:delm[arks]
{marks}Delete the specified marks. Marks that can be deletedinclude A-Z and 0-9. You cannot delete the ' mark.They can be specified by giving the list of marknames, or with a range, separated with a dash. Spacesare ignored. Examples:
:delmarks a deletes mark a:delmarks a b 1 deletes marks a, b and 1:delmarks Aa deletes marks A and a:delmarks p-z deletes marks in the range p to z:delmarks ^.[] deletes marks ^ . [ ]:delmarks \" deletes mark "
:delm[arks]!Delete all marks for the current buffer, but not marksA-Z or 0-9. Also clear the
changelist.
A mark is not visible in any way. It is just a position in the file that isremembered. Do not confuse marks with named registers, they are totallyunrelated.
'a - 'zlowercase marks, valid within one file'A - 'Zuppercase marks, also called file marks, valid between files'0 - '9numbered marks, set from
shada file
Lowercase marks 'a to 'z are remembered as long as the file remains in thebuffer list. If you remove the file from the buffer list, all its marks arelost. If you 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 undoand redo.
Uppercase marks 'A to 'Z include the file name. You can use them to jump fromfile to file. You can only use an uppercase mark with an operator if the markis in the current file. The line number of the mark remains correct, even ifyou insert/delete lines or edit another file for a moment. When the
'shada'option is not empty, uppercase marks are kept in the .shada file. See
shada-file-marks.
Numbered marks '0 to '9 are quite different. They can not be set directly.They are only present when using a shada file
shada-file. Basically '0is the location of the cursor when you last exited Vim, '1 the last but onetime, etc. Use the "r" flag in
'shada' to specify files for which noNumbered mark should be stored. See
shada-file-marks.
'[`['[[To the first character of the previously changed,or yanked text. Also set when writing the buffer.
']`]']]To the last character of the previously changed oryanked text. Also set when writing the buffer.
After executing an operator the Cursor is put at the beginning of the textthat was operated upon. After a put command ("p" or "P") the cursor issometimes placed at the first inserted line and sometimes on the last insertedcharacter. 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']". Afterinserting several lines with the "p" command you want to jump to the lowestinserted line: "p']". This also works for text that has been inserted.
Note: After deleting text, the start and end positions are the same, exceptwhen using blockwise Visual mode. These commands do not work when no changewas made yet in the current file.
'<`<'<<To the first line or character of the last selectedVisual area in the current buffer. For block mode itmay also be the last character in the first line (tobe able to define the block).
'>`>'>>To the last line or character of the last selectedVisual area in the current buffer. For block mode itmay also be the first character of the last line (tobe able to define the block). Note that
'selection'applies, the position may be just after the Visualarea.
''``'' ``To the position before the latest jump, or where thelast "m'" or "m`" command was given. Not set when the
:keepjumps command modifier was used.Also see
restore-position.
'quote`quote'""To the cursor position when last exiting the currentbuffer. Defaults to the first character of the firstline. See
last-position-jump for how to use thisfor each opened file.Only one position is remembered per buffer, not onefor each window. As long as the buffer is visible ina window the position won't be changed. Mark is alsoreset when
:wshada is run.
'^`^'^^To the position where the cursor was the last timewhen Insert mode was stopped. This is used by the
gi command. Not set when the
:keepjumps commandmodifier was used.
'.`.'..To the position where the last change was made. Theposition is at or near where the change started.Sometimes a command is executed as several changes,then the position can be near the end of what thecommand changed. For example when inserting a word,the position will be on the last character.To jump to older changes use
g;.
':`:':In a prompt buffer, the start of the current prompt.Text from this line until end of buffer will besubmitted when the user submits the prompt.
'(`('((To the start of the current sentence, like the |(|command.
')`)'))To the end of the current sentence, like the |)|command.
'{`{'{{To the start of the current paragraph, like the |{|command.
'}`}'}}To the end of the current paragraph, like the |}|command.
These commands are not marks themselves, but jump to a mark:
]']'[count] times to next line with a lowercase mark belowthe cursor, on the first non-blank character in theline.
]`]`[count] times to lowercase mark after the cursor.
['['[count] times to previous line with a lowercase markbefore the cursor, on the first non-blank character inthe line.
[`[[count] times to lowercase mark before the cursor.
:loc[kmarks]
{command}:loc:lock:lockmarksExecute
{command} without adjusting marks. This isuseful when changing text in a way that the line countwill be the same when the change has completed.
WARNING: When the line count does change, marks belowthe change will keep their line number, thus move toanother text line.These items will not be adjusted for deleted/insertedlines:
lower case letter marks 'a - 'z
upper case letter marks 'A - 'Z
numbered marks '0 - '9
last insert position '^
last change position '.
last affected text area '[ and ']
the Visual area '< and '
- line numbers in placed signs- line numbers in quickfix positions- positions in the |jumplist|- positions in the |tagstack|These items will still be adjusted:- previous context mark ''- the cursor position- the view of a window on a buffer- folds- diffs
:kee[pmarks]
{command}:kee:keep:keepmarksCurrently only has effect for the filter command
:range!:
When the number of lines after filtering is equal to or larger than before, all marks are kept at the same line number.
When the number of lines decreases, the marks in the lines that disappeared are deleted.In any case the marks below the filtered text havetheir line numbers adjusted, thus stick to the text,as usual.When the 'R' flag is missing from
'cpoptions' this hasthe same effect as using ":keepmarks".
:keepj:keepjumps:keepj[umps]
{command}Moving around in
{command} does not change the
'',
'. and
'^ marks, the
jumplist or the
changelist.Useful when making a change or inserting textautomatically and the user doesn't want to go to thisposition. E.g., when updating a "Last change"timestamp in the first line:
:let lnum = line("."):keepjumps normal gg:call SetLastChange():keepjumps exe "normal " .. lnum .. "G" Note that ":keepjumps" must be used for every command.When invoking a function the commands in that functioncan still change the jumplist. Also, for:keepjumps exe 'command ' the "command" won't keepjumps. Instead use::exe 'keepjumps command'
A "jump" is a command that normally moves the cursor several lines away. Ifyou make the cursor "jump" the position of the cursor before the jump isremembered. You can return to that position with the "''" and "``" commands,unless the line containing that position was changed or deleted. Thefollowing commands are "jump" commands: "'", "`", "G", "/", "?", "n", "N","%", "(", ")", "[[", "]]", "{", "}", ":s", ":tag", "L", "M", "H" and thecommands that start editing a new file.
CTRL-OCTRL-OGo to [count] Older cursor position in jump list(not a motion command).
<Tab>or
CTRL-I<Tab>CTRL-IGo to [count] newer cursor position in jump list(not a motion command).
:ju:jumps:ju[mps]Print the jump list (not a motion command).
jumplistJumps are remembered in a jump list. With the
CTRL-O and
CTRL-I command youcan go to cursor positions before older jumps, and back again. Thus you canmove up and down the list. There is a separate jump list for each window.The maximum number of entries is fixed at 100.
For example, after three jump commands you have this jump list:
jump line col file/text 3 1 0 some text 2 70 0 another line 1 1154 23 end.>
The "file/text" column shows the file name, or the text at the jump if it isin the current file (an indent is removed and a long line is truncated to fitin the window).
The marker ">" indicates the current position in the jumplist. It may not beshown when filtering the
:jumps command using
:filterYou are currently in line 1167. If you then use the
CTRL-O command, thecursor is put in line 1154. This results in:
jump line col file/text 2 1 0 some text 1 70 0 another line> 0 1154 23 end. 1 1167 0 foo bar
The pointer will be set at the last used jump position. The nextCTRL-Ocommand will use the entry above it, the nextCTRL-I command will use theentry below it. If the pointer is below the last entry, this indicates thatyou did not use aCTRL-I orCTRL-O before. In this case theCTRL-O commandwill cause the cursor position to be added to the jump list, so you can getback to the position before theCTRL-O. In this case this is line 1167.
With moreCTRL-O commands you will go to lines 70 and 1. If you useCTRL-Iyou can go back to 1154 and 1167 again. Note that the number in the "jump"column indicates the count for theCTRL-O orCTRL-I command that takes you tothis position.
If you use a jump command, the current line number is inserted at the end ofthe jump list. If the same line was already in the jump list, it is removed.The result is that when repeatingCTRL-O you will get back to old positionsonly once.
When the
:keepjumps command modifier is used, jumps are not stored in thejumplist. Jumps are also not stored in other cases, e.g., in a
:globalcommand. You can explicitly add a jump by setting the ' mark with "m'". Notethat calling setpos() does not do this.
After the
CTRL-O command that got you into line 1154 you could give anotherjump command (e.g., "G"). The jump list would then become:
jump line col file/text 4 1 0 some text 3 70 0 another line 2 1167 0 foo bar 1 1154 23 end.>
The line numbers will be adjusted for deleted and inserted lines. This failsif you stop editing a file without writing, like with ":n!".
When you split a window, the jumplist will be copied to the new window.
If you have included the ' item in the
'shada' option the jumplist will bestored in the ShaDa file and restored when starting Vim.
jumplist-stackWhen
'jumpoptions' option includes "stack", the jumplist behaves like the tagstack. When jumping to a new location from the middle of the jumplist, thelocations after the current position will be discarded. With this option setyou can move through a tree of jump locations. When going back up a branchand then down another branch,
CTRL-O still takes you further up the tree.
Given a jumplist like the following in which
CTRL-O has been used to move backthree times to location X:
jump line col file/text 2 1260 8 mark.c<-- location X-2 1 685 0 eval.c<-- location X-1> 0 462 36 eval.c<-- location X 1 479 39 eval.c 2 213 2 mark.c 3 181 0 mark.c
jumping to (new) location Y results in the locations after the currentlocations being removed:
jump line col file/text 3 1260 8 mark.c<-- location X-2 2 685 0 eval.c<-- location X-1 1 462 36 eval.c<-- location X>
Then, when yet another location Z is jumped to, the new location Y appearsdirectly after location X in the jumplist and location X remains in the sameposition relative to the locations (X-1, X-2, etc., ...) that had been beforeit prior to the original jump from X to Y:
jump line col file/text 4 1260 8 mark.c<-- location X-2 3 685 0 eval.c<-- location X-1 2 462 36 eval.c<-- location X 1 100 0 buffer.c<-- location Y>
When making a change the cursor position is remembered. One position isremembered for every change that can be undone, unless it is close to aprevious change. Two commands can be used to jump to positions of changes,also those that have been undone:
g;E662g;Go to [count] older position in change list.If [count] is larger than the number of older changepositions go to the oldest change.If there is no older change an error message is given.(not a motion command)
g,E663g,Go to [count] newer position in change list.Just like
g; but in the opposite direction.(not a motion command)
When using a count you jump as far back or forward as possible. Thus you canuse "999g;" to go to the first change for which the position is stillremembered. The number of entries in the change list is fixed and is the sameas for the
jumplist.
When two undo-able changes are in the same line and at a column position lessthan
'textwidth' apart only the last one is remembered. This avoids that asequence of small changes in a line, for example "xxxxx", adds many positionsto the change list. When
'textwidth' is zero
'wrapmargin' is used. When thatalso isn't set a fixed number of 79 is used. Detail: For the computationsbytes are used, not characters, to avoid a speed penalty (this only mattersfor multibyte encodings).
Note that when text has been inserted or deleted the cursor position might bea bit different from the position of the change. Especially when lines havebeen deleted.
When the:keepjumps command modifier is used the position of a change is notremembered.
:changes:changesPrint the change list. A ">" character indicates thecurrent position. Just after a change it is below thenewest entry, indicating that
g; takes you to thenewest entry position. The first column indicates thecount needed to take you to this position. Example:
change line col text
3 9 8 bla bla bla 2 11 57 foo is a bar 1 14 54 the latest changed line
The `3g;` command takes you to line 9. Then theoutput of `:changes` is: change line col text ~ > 0 9 8 bla bla bla 1 11 57 foo is a bar 2 14 54 the latest changed lineNow you can use "g," to go to line 11 and "2g," to goto line 14.
%%Find the next item in this line after or under thecursor and jump to its match.
inclusive motion.Items can be:([{}])parenthesis or (curly/square) brackets(this can be changed with the
'matchpairs' option)
/* */ start or end of C-style comment#if, #ifdef, #else, #elif, #endifC preprocessor conditionals (when thecursor is on the # or no ([{is following)For other items the matchit plugin can be used, see|matchit|. This plugin also helps to skip matches incomments.
When
'cpoptions' contains "M"
cpo-M backslashesbefore parens and braces are ignored. Without "M" thenumber of backslashes matters: an even number doesn'tmatch with an odd number. Thus in "( \) )" and "\( (\)" the first and last parenthesis match.
When the '%' character is not present in
'cpoptions'cpo-%, parens and braces inside double quotes areignored, unless the number of parens/braces in a lineis uneven and this line and the previous one does notend in a backslash. '(', '{', '[', ']', '}' and ')'are also ignored (parens and braces inside singlequotes). Note that this works fine for C, but not forPerl, where single quotes are used for strings.
Nothing special is done for matches in comments. Youcan either use the |matchit| plugin or put quotes aroundmatches.
No count is allowed,
{count}% jumps to a line
{count}percentage down the file
N%. Using '%' on#if/#else/#endif makes the movement linewise.
[([(Go to [count] previous unmatched '('.
exclusive motion.
[{[{Go to [count] previous unmatched '{'.
exclusive motion.
The above four commands can be used to go to the start or end of the currentcode block. It is like doing "%" on the "(", ")", "{" or "}" at the otherend 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:",[{ willbring you back to the switch statement.
]m]mGo to [count] next start of a method (for Java orsimilar structured language). When not before thestart of a method, jump to the start or end of theclass.
exclusive motion.
]M]MGo to [count] next end of a method (for Java orsimilar structured language). When not before the endof a method, jump to the start or end of the class.
exclusive motion.
[m[mGo to [count] previous start of a method (for Java orsimilar structured language). When not after thestart of a method, jump to the start or end of theclass. When no '{' is found before the cursor this isan error.
exclusive motion.
[M[MGo to [count] previous end of a method (for Java orsimilar structured language). When not after theend of a method, jump to the start or end of theclass. When no '}' is found before the cursor this isan error.
exclusive motion.
The above four commands assume that the file contains a class with methods.The class definition is surrounded in '{' and '}'. Each method in the classis also surrounded with '{' and '}'. This applies to the Java language. Thefile looks like this:
// commentclass foo { int method_one() { body_one(); } int method_two() { body_two(); }}[To try this out copy the text and put it in a new buffer, the help text aboveconfuses the jump commands]
Starting with the cursor on "body_two()", using "[m" will jump to the '{' atthe start of "method_two()" (obviously this is much more useful when themethod is long!). Using "2[m" will jump to the start of "method_one()".Using "3[m" will jump to the start of the class.
[#[#Go to [count] previous unmatched "#if" or "#else".
exclusive motion.
]#]#Go to [count] next unmatched "#else" or "#endif".
exclusive motion.
These two commands work in C programs that contain #if/#else/#endifconstructs. It brings you to the start or end of the #if/#else/#endif wherethe current line is included. You can then use "%" to go to the matchingline.
[star[/[* or [/Go to [count] previous start of a C comment "/*".
exclusive motion.
HHTo line [count] from top (Home) of window (default:first line on the window) on the first non-blankcharacter
linewise. See also
'startofline' option.Cursor is adjusted for
'scrolloff' option, unless anoperator is pending, in which case the text mayscroll. E.g. "yH" yanks from the first visible lineuntil the cursor line (inclusive).
LLTo line [count] from bottom of window (default: Lastline on the window) on the first non-blank character
linewise. See also
'startofline' option.Cursor is adjusted for
'scrolloff' option, unless anoperator is pending, in which case the text mayscroll. E.g. "yL" yanks from the cursor to the lastvisible line.
<LeftMouse>Moves to the position on the screen where the mouseclick is
exclusive. See also
<LeftMouse>. If theposition is in a status line, that window is made theactive window and the cursor is not moved.