根据:h mark
:
m[ m]
m[ or m] Set the '[ or '] mark. Useful when an operator is
to be simulated by multiple commands. (does not move
the cursor, this is not a motion command).
m<
和m>
非常有用,但上面的描述对我来说太模糊了,我找不到任何例子。
答案 0 :(得分:2)
正如melpomeme所述,您可以使用vim中的:help '[
命令查看以下区域:
*'[* *`[*
'[ `[ To the first character of the previously changed
or yanked text. {not in Vi}
*']* *`]*
'] `] To the last character of the previously changed or
yanked 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 change
was made yet in the current file.
在大马克章节中:
7. Marks *mark-motions* *E20* *E78*
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.
*m* *mark* *Mark*
m{a-zA-Z} Set mark {a-zA-Z} at cursor position (does not move
the cursor, this is not a motion command).
*m'* *m`*
m' or m` Set the previous context mark. This can be jumped to
with the "''" or "``" command (does not move the
cursor, this is not a motion command).
*m[* *m]*
m[ or m] Set the |'[| or |']| mark. Useful when an operator is
to be simulated by multiple commands. (does not move
the 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, this
is not a motion command).
Note that the Visual mode cannot be set, only the
start and end position.
*:ma* *:mark* *E191*
:[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 can
be 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 (not
a motion command when in another file). {not in Vi}
*g'* *g'a* *g`* *g`a*
g'{mark} g`{mark}
Jump to the {mark}, but don't change the jumplist when
jumping within the current buffer. Example: >
g`"
< jumps to the last known position in a file. See
$VIMRUNTIME/vimrc_example.vim.
Also see |:keepjumps|.
{not in Vi}
*:marks*
:marks List all the current marks (not a motion command).
The |'(|, |')|, |'{| and |'}| marks are not listed.
The first column has number zero.
{not in Vi}
*E283*
: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}
*:delm* *:delmarks*
:delm[arks] {marks} Delete the specified marks. Marks that can be deleted
include A-Z and 0-9. You cannot delete the ' mark.
They can be specified by giving the list of mark
names, or with a range, separated with a dash. Spaces
are 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 "
< {not in Vi}
:delm[arks]! Delete all marks for the current buffer, but not marks
A-Z or 0-9.
{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, all its marks are
lost. 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 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 |viminfo-file|. Basically '0
is the location of the cursor when you last exited Vim, '1 the last but one
time, etc. Use the "r" flag in 'viminfo' to specify files for which no
Numbered mark should be stored. See |viminfo-file-marks|.
*'[* *`[*
'[ `[ To the first character of the previously changed
or yanked text. {not in Vi}
*']* *`]*
'] `] To the last character of the previously changed or
yanked 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 change
was made yet in the current file.
*'<* *`<*
'< `< To the first line or character of the last selected
Visual area in the current buffer. For block mode it
may also be the last character in the first line (to
be able to define the block). {not in Vi}.
*'>* *`>*
'> `> To the last line or character of the last selected
Visual area in the current buffer. For block mode it
may also be the first character of the last line (to
be able to define the block). Note that 'selection'
applies, the position may be just after the Visual
area. {not in Vi}.
*''* *``*
'' `` To the position before the latest jump, or where the
last "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 current
buffer. Defaults to the first character of the first
line. See |last-position-jump| for how to use this
for each opened file.
Only one position is remembered per buffer, not one
for each window. As long as the buffer is visible in
a window the position won't be changed.
{not in Vi}.
*'^* *`^*
'^ `^ To the position where the cursor was the last time
when Insert mode was stopped. This is used by the
|gi| command. Not set when the |:keepjumps| command
modifier was used. {not in Vi}
*'.* *`.*
'. `. To the position where the last change was made. The
position 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 the
command changed. For example when inserting a word,
the position will be on the last character.
To jump to older changes use |g;|.
{not in Vi}
*'(* *`(*
'( `( To the start of the current sentence, like the |(|
command. {not in Vi}
*')* *`)*
') `) To the end of the current sentence, like the |)|
command. {not in Vi}
*'{* *`{*
'{ `{ To the start of the current paragraph, like the |{|
command. {not in Vi}
*'}* *`}*
'} `} To the end of the current paragraph, like the |}|
command. {not in Vi}
These commands are not marks themselves, but jump to a mark:
*]'*
]' [count] times to next line with a lowercase mark below
the cursor, on the first non-blank character in the
line. {not in Vi}
*]`*
]` [count] times to lowercase mark after the cursor. {not
in Vi}
*['*
[' [count] times to previous line with a lowercase mark
before the cursor, on the first non-blank character in
the line. {not in Vi}
*[`*
[` [count] times to lowercase mark before the cursor.
{not in Vi}
:loc[kmarks] {command} *:loc* *:lockmarks*
Execute {command} without adjusting marks. This is
useful when changing text in a way that the line count
will be the same when the change has completed.
WARNING: When the line count does change, marks below
the change will keep their line number, thus move to
another text line.
These items will not be adjusted for deleted/inserted
lines:
- lower case letter marks 'a - 'z
- upper case letter marks 'A - 'Z
- numbered marks '0 - '9
- last insert position '^
- last change position '.
- 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* *:keepmarks*
Currently 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 have
their line numbers adjusted, thus stick to the text,
as usual.
When the 'R' flag is missing from 'cpoptions' this has
the 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 text
automatically and the user doesn't want to go to this
position. 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 function
can still change the jumplist. Also, for
":keepjumps exe 'command '" the "command" won't keep
jumps. Instead use: ":exe 'keepjumps command'"
或者你也可以在这里看到这个摘录:http://vim.wikia.com/wiki/Using_marks格式略有不同: