yank

visual mode操作

The operators that can be used are:
switch case |v_~|
d delete |v_d|
c change (4) |v_c|
y yank |v_y|
​>	shift right (4)					|v_>|
​<	shift left (4)					|v_<|
​!	filter through external command (1)		|v_!|
​=	filter through 'equalprg' option command (1)	|v_=|
​gq	format lines to 'textwidth' length (1)		|v_gq|

The objects that can be used are:
aw a word (with white space) |v_aw|
iw inner word |v_iw|
aW a WORD (with white space) |v_aW|
iW inner WORD |v_iW|
as a sentence (with white space) |v_as|
is inner sentence |v_is|
ap a paragraph (with white space) |v_ap|
ip inner paragraph |v_ip|
ab a () block (with parentheses) |v_ab|
ib inner () block |v_ib|
aB a } block (with braces) v_aB|
iB inner {
block |v_iB|
at a <tag> </tag> block (with tags) |v_at|
it inner <tag> </tag> block |v_it|
a< a <> block (with <>) |v_a<|
i< inner <> block |v_i<|
a[ a [] block (with []) |v_a[|
i[ inner [] block |v_i[|
a" a double quoted string (with quotes) |v_aquote|
i" inner double quoted string |v_iquote|
a' a single quoted string (with quotes) |v_a'|
i' inner simple quoted string |v_i'|
a a string in backticks (with backticks) |v_a|
i inner string in backticks |v_i|

Additionally the following commands can be used:
start Ex command for highlighted lines (1) |v_:|
r change (4) |v_r|
s change |v_s|
C change (2)(4) |v_C|
S change (2) |v_S|
R change (2) |v_R|
x delete |v_x|
D delete (3) |v_D|
X delete (2) |v_X|
Y yank (2) |v_Y|
p put |v_p|
P put without overwriting registers |v_P|
J join (1) |v_J|
U make uppercase |v_U|
u make lowercase |v_u|
^] find tag |v_CTRL-]|
I block insert |v_b_I|
A block append |v_b_A|
  1. Always whole lines, see |:visual_example|.
  2. Whole lines when not using CTRL-V.
  3. Whole lines when not using CTRL-V, delete until the end of the line when using CTRL-V.
  4. When using CTRL-V operates on the block only.

Note that the ":vmap" command can be used to specifically map keys in Visual
mode. For example, if you would like the "/" command not to extend the Visual
area, but instead take the highlighted text and search for that: >
:vmap / y/<C-R>"<CR>
(In the <> notation |<>|, when typing it you should type it literally; you
need to remove the 'B' flag from 'cpoptions'.)

If you want to give a register name using the """ command, do this just before
typing the operator character: "v{move-around}"xd".

If you want to give a count to the command, do this just before typing the
operator character: "v{move-around}3>" (move lines 3 indents to the right).

​						*{move-around}*

The {move-around} is any sequence of movement commands. Note the difference
with {motion}, which is only ONE movement command.

Another way to operate on the Visual area is using the |/%V| item in a
pattern. For example, to replace all '(' in the Visual area with '#': >

​:'<,'>s/\%V(/#/g

Note that the "'<,'>" will appear automatically when you press ":" in Visual
mode.

==============================================================================
5. Blockwise operators blockwise-operators

Reminder: Use 'virtualedit' to be able to select blocks that start or end
after the end of a line or halfway through a tab.

Visual-block Insert v_b_I
With a blockwise selection, I{string}<ESC> will insert {string} at the start
of block on every line of the block, provided that the line extends into the
block. Thus lines that are short will remain unmodified. TABs are split to
retain visual columns. Works only for adding text to a line, not for
deletions. See |v_b_I_example|.

Visual-block Append v_b_A
With a blockwise selection, A{string}<ESC> will append {string} to the end of
block on every line of the block. There is some differing behavior where the
block RHS is not straight, due to different line lengths:

  1. Block was created with <C-v>$
    In this case the string is appended to the end of each line.
  2. Block was created with <C-v>{move-around}
    In this case the string is appended to the end of the block on each line,
    and whitespace is inserted to pad to the end-of-block column.
    See |v_b_A_example|.
    Note: "I" and "A" behave differently for lines that don't extend into the
    selected block. This was done intentionally, so that you can do it the way
    you want.
    Works only for adding text to a line, not for deletions.

Visual-block change v_b_c
All selected text in the block will be replaced by the same text string. When
using "c" the selected text is deleted and Insert mode started. You can then
enter text (without a line break). When you hit <Esc>, the same string is
inserted in all previously selected lines.

Visual-block Change v_b_C
Like using "c", but the selection is extended until the end of the line for
all lines.

​							*v_b_<*

Visual-block Shift v_b_>
The block is shifted by 'shiftwidth'. The RHS of the block is irrelevant. The
LHS of the block determines the point from which to apply a right shift, and
padding includes TABs optimally according to 'ts' and 'et'. The LHS of the
block determines the point up to which to shift left.
See |v_b_>example|.
See |v_b
<_example|.

Visual-block Replace v_b_r
Every screen char in the highlighted region is replaced with the same char, ie
TABs are split and the virtual whitespace is replaced, maintaining screen
layout.
See |v_b_r_example|.

==============================================================================
6. Repeating visual-repeat

When repeating a Visual mode operator, the operator will be applied to the
same amount of text as the last time:

  • Linewise Visual mode: The same number of lines.
  • Blockwise Visual mode: The same number of lines and columns.
  • Normal Visual mode within one line: The same number of characters.
  • Normal Visual mode with several lines: The same number of lines, in the
    last line the same number of characters as in the last line the last time.
    The start of the text is the Cursor position. If the "$" command was used as
    one of the last commands to extend the highlighted text, the repeating will
    be applied up to the rightmost column of the longest line. Any count passed
    to the . command is not used.

==============================================================================
7. Examples visual-examples

​						*:visual_example*

Currently the ":" command works on whole lines only. When you select part of
a line, doing something like ":!date" will replace the whole line. If you
want only part of the line to be replaced you will have to make a mapping for
it. In a future release ":" may work on partial lines.

Here is an example, to replace the selected text with the output of "date": >
:vmap _a <Esc>>a<CR><Esc><i<CR><Esc>!!date<CR>kJJ

(In the <> notation |<>|, when typing it you should type it literally; you
need to remove the 'B' flag from 'cpoptions')

What this does is:
<Esc> stop Visual mode
> go to the end of the Visual area a<CR><Esc> break the line after the Visual area < jump to the start of the Visual area
i<CR><Esc> break the line before the Visual area
!!date<CR> filter the Visual text through date
kJJ Join the lines back together

​						*visual-search*

Here is an idea for a mapping that makes it possible to do a search for the
selected text: >
:vmap X y/<C-R>"<CR>

(In the <> notation |<>|, when typing it you should type it literally; you
need to remove the 'B' flag from 'cpoptions')

Note that special characters (like '.' and '*') will cause problems.

Visual-block Examples blockwise-examples
With the following text, I will indicate the commands to produce the block and
the results below. In all cases, the cursor begins on the 'a' in the first
line of the test text.
The following modeline settings are assumed ":ts=8:sw=4:".

It will be helpful to
:set hls
/<TAB>
where <TAB> is a real TAB. This helps visualise the operations.