首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在正常模式下的vim中“vaw”是什么意思(还有“caw”和“daw”)?

在正常模式下的vim中“vaw”是什么意思(还有“caw”和“daw”)?
EN

Stack Overflow用户
提问于 2011-09-01 15:45:31
回答 3查看 5.8K关注 0票数 8

我在vim中有:

代码语言:javascript
复制
foo barba[r]bar
foo

[]表示光标位置

当我使用vaw或viw时,工具栏会变得很高。这是可以的。

但我想知道--为什么?V代表视觉模式,a-我不知道为什么,w表示新单词的开头。

我还检查了caw和ciw。第一个删除工具栏,并将光标留在foo后没有空格,第二个将在foo后留下空格,两个都进入插入模式...

那么它为什么会起作用呢?在vim帮助中有什么参考吗?有人能把它翻译成vim语言吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-09-01 15:47:08

参见:help text-object。这比这里任何人都能更好地解释这一切。

下面是整个部分:

代码语言:javascript
复制
6. Text object selection            *object-select* *text-objects*
                        *v_a* *v_i*

This is a series of commands that can only be used while in Visual mode or
after an operator.  The commands that start with "a" select "a"n object
including white space, the commands starting with "i" select an "inner" object
without white space, or just the white space.  Thus the "inner" commands
always select less text than the "a" commands.

These commands are {not in Vi}.
These commands are not available when the |+textobjects| feature has been
disabled at compile time.
                            *v_aw* *aw*
aw          "a word", select [count] words (see |word|).
            Leading or trailing white space is included, but not
            counted.
            When used in Visual linewise mode "aw" switches to
            Visual characterwise mode.

                            *v_iw* *iw*
iw          "inner word", select [count] words (see |word|).
            White space between words is counted too.
            When used in Visual linewise mode "iw" switches to
            Visual characterwise mode.

                            *v_aW* *aW*
aW          "a WORD", select [count] WORDs (see |WORD|).
            Leading or trailing white space is included, but not
            counted.
            When used in Visual linewise mode "aW" switches to
            Visual characterwise mode.

                            *v_iW* *iW*
iW          "inner WORD", select [count] WORDs (see |WORD|).
            White space between words is counted too.
            When used in Visual linewise mode "iW" switches to
            Visual characterwise mode.

                            *v_as* *as*
as          "a sentence", select [count] sentences (see
            |sentence|).
            When used in Visual mode it is made characterwise.

                            *v_is* *is*
is          "inner sentence", select [count] sentences (see
            |sentence|).
            When used in Visual mode it is made characterwise.

                            *v_ap* *ap*
ap          "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_ip* *ip*
ip          "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.  This
            goes backwards to the [count] unclosed '[', and finds
            the matching ']'.  The enclosed text is selected,
            including the '[' and ']'.
            When used in Visual mode it is made characterwise.

i]                      *v_i]* *v_i[* *i]* *i[*
i[          "inner [] block", select [count] '[' ']' blocks.  This
            goes backwards to the [count] unclosed '[', and finds
            the matching ']'.  The enclosed text is selected,
            excluding the '[' and ']'.
            When used in Visual mode it is made characterwise.

a)                          *v_a)* *a)* *a(*
a(                          *v_ab* *v_a(* *ab*
ab          "a block", select [count] blocks, from "[count] [(" to
            the matching ')', including the '(' and ')' (see
            |[(|).  Does not include white space outside of the
            parenthesis.
            When used in Visual mode it is made characterwise.

i)                          *v_i)* *i)* *i(*
i(                          *v_ib* *v_i(* *ib*
ib          "inner block", select [count] blocks, from "[count] [("
            to the matching ')', excluding the '(' and ')' (see
            |[(|).
            When used in Visual mode it is made characterwise.

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 '>'.
            When used in Visual mode it is made characterwise.

i>                      *v_i>* *v_i<* *i>* *i<*
i<          "inner <> block", select [count] <> blocks, from
            the [count]'th unmatched '<' backwards to the matching
            '>', excluding the '<' and '>'.
            When used in Visual mode it is made characterwise.

                        *v_at* *at*
at          "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 characterwise.

                        *v_it* *it*
it          "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 characterwise.

a}                          *v_a}* *a}* *a{*
a{                          *v_aB* *v_a{* *aB*
aB          "a Block", select [count] Blocks, from "[count] [{" to
            the matching '}', including the '{' and '}' (see
            |[{|).
            When used in Visual mode it is made characterwise.

i}                          *v_i}* *i}* *i{*
i{                          *v_iB* *v_i{* *iB*
iB          "inner Block", select [count] Blocks, from "[count] [{"
            to the matching '}', excluding the '{' and '}' (see
            |[{|).
            When used in Visual mode it is made characterwise.

a"                          *v_aquote* *aquote*
a'                          *v_a'* *a'*
a`                          *v_a`* *a`*
            "a quoted string".  Selects the text from the previous
            quote until the next quote.  The 'quoteescape' option
            is used to skip escaped quotes.
            Only works within one line.
            When the cursor starts on a quote, Vim will figure out
            which quote pairs form a string by searching from the
            start of the line.
            Any trailing white space is included, unless there is
            none, then leading white space is included.
            When used in Visual mode it is made characterwise.
            Repeating this object in Visual mode another string is
            included.  A count is currently not used.

i"                          *v_iquote* *iquote*
i'                          *v_i'* *i'*
i`                          *v_i`* *i`*
            Like a", a' and a`, but exclude the quotes and
            repeating won't extend the Visual selection.
            Special case: With a count of 2 the quotes are
            included, but no extra white space as with a"/a'/a`.

When used after an operator:
For non-block objects:
    For the "a" commands: 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 the "inner" commands: If the cursor was on the object, the
    operator applies to the object.  If the cursor was on white space, the
    operator applies to the white space.
For a block object:
    The operator applies to the block where the cursor is in, or the block
    on which the cursor is on one of the braces.  For the "inner" commands
    the surrounding braces are excluded.  For the "a" commands, the braces
    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, or both for the "a" objects.  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")       |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*
    "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          *daB*

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 "daw": "dw"
deletes from the cursor position to the start of the next word, "daw" deletes
the word under the cursor and the space after or before it.

请注意,您可以使用两个命令创建自己的文本对象(例如,您希望“K”成为新的文本对象:在操作员模式下,您希望选择三个字符,光标位于中心;在视觉模式下,您希望将选择范围扩展1个字符至两端(假设光标位于选择范围的末尾):

代码语言:javascript
复制
"operator-pending mapping
onoremap K :normal! hv2l<return>
"visual mapping (xmap preferred over vmap because vmap also works in select mode)
"note that in visual mode o goes to the other end. Therefore this will expand selection if you were at the end and restrict it otherwise.
xnoremap K ohol
票数 28
EN

Stack Overflow用户

发布于 2011-09-01 15:52:41

它与文本对象相关。

  • vaw的意思是“选择(视觉模式)一个词(包括下面的whitespace)"
  • caw意思是”更改一个词(包括下面的whitespace)"
  • daw )意思是“删除一个词(包括后面的空格)”

如果你使用"i“,它是相同的,除了它是一个”内部“选择,所以它不会选择周围的空格。

还有其他文本对象,如:

  • p表示段落,
  • 表示句子
  • b表示数据块
  • (适用于parenthesis
  • ] for brackets
  • etc

所以你使用dip来删除当前段落。

有关更多详细信息,请参阅:help text-objects

这是一个非常强大的Vim特性。一旦你掌握了文本对象,你将会在大多数操作中使用它们。例如,如果你想重新格式化一个(类似C的)函数,你可以使用=i}就可以了!(=是refomat的命令,i}是当前{块的作用域)

票数 6
EN

Stack Overflow用户

发布于 2011-09-01 15:51:31

看见

代码语言:javascript
复制
:he text-objects

vaw -选择“周围”字。视频-选择“内部”字。

您给出的示例不会显示这两个操作之间的区别。

尝试使用单引号或双引号的单词,您将看到不同之处:

代码语言:javascript
复制
"Sasq[u]atch"

尝试上面的viw和vaw,你就会看到它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7267375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档