我正在玩vim冒险游戏,卡住了。我需要一个Vim命令来删除红色键位。我以为 dd
命令可以实现,但那只会删除当前行。
使用 das 或 dis 删除一个句子。使用 dap 或 dip 删除一个段落。有关详情,请参见:help text-objects
。与您的问题无关,请参见此插件的维基页面,以获取提供其他非常有用的文本对象的插件。
d
删除下一个对象。 s
表示句子。 a
表示“周围”,i
表示“内部”。它们之间的区别在于空格。虽然人们可能期望使用 ds
或 dS
(或类似的)来删除光标到句子结尾/开头的内容,但实际上需要使用 (
和 )
来完成此操作。 - mazunkivim-sandwich
插件,则 das
映射将无法正常工作。请尝试输入 da
,等待光标开始闪烁,然后键入 s
。请参阅 https://github.com/machakann/vim-sandwich/issues/62。 - user10706046)
跳到下一句的开头,所以d)
会删除(从光标处)直到下一句的开头。Vim使用.
来检测句子,这意味着句号+空格。这意味着如果光标位于分隔两个句子的句点或空格上,d)
将会有一些问题,并且只会删除到下一句的第一个字符(这意味着它会删除一个空格或句点和空格,这几乎永远不是想要的结果)。das
将按你预期的方式工作,删除句子和分隔符(句点+空格)。
如果你特别想移动(并删除)一个句子中的最后一个字符,根据这个vi.SE答案,它更加复杂:
dk
删除当前行及其上面的一行,或者使用dj
删除当前行及其下面的一行。要删除从光标所在位置到句子末尾的内容,请使用字母"d)"。 "d"是删除命令对象,后面跟着运动对象“)”将光标(和删除过程)推进到句子的末尾。
要“围绕”一个句子进行删除,包括所有额外的空格,请使用“das”(删除句子周围)。或者要删除句子内部而不是所有空格,则使用“dis”(删除句子内部)。
一旦您理解了VIM语言,就可以轻松记忆大量操作。使用此表格了解VIM的词汇:
COUNT NUMERAL + TEXT OBJECT COMMAND + MOTION(或者OPERATORS) “3das”将执行“3次删除周围的句子”
因此,如果实际可行,您可以放置一个数字后面跟着一个命令:
d=delete
y=yank (into memory buffer to "put" later)
c=change (delete then insert new text)
然后是一个动作:
) = move cursor to end of sentence
( = move cursor to beginning of prior sentence
} = move cursor to the next paragraph
{ = move cursor to the beginning of the prior paragraph
w = move cursor to next word
b = move cursor back a word
$ = move cursor to the end of the logical line
0 = (zero) move cursor to the beginning of the logical line
G = move cursor to the end of the file
gg = move cursor to the beginning of the file
h, j, k, or l (you might have to look those up)
或者不使用运动,而是使用以下方式定义一个区域字段:
a = around
i = inside
s = sentence
p = paragraph
w = word
t = xml-tag <tag example> lots of text between tags </tag example>
< or > = inside or around a tag, frequently found in xml documents
{ [ ( ) ] } = inside or around any type of bracket ...
... {a large area [some more (a little stuff) things] of a great many things }
我实际上在帮助文件中发现这张表格是块命令的最佳概述:
"dl" delete character (alias: "x")
"diw" delete inner word
"daw" delete a word
"diW" delete inner WORD (see |WORD|)
"daW" delete a WORD (see |WORD|)
"dgn" delete the next search pattern match
"dd" delete one line
"dis" delete inner sentence
"das" delete a sentence
"dib" delete inner '(' ')' block
"dab" delete a '(' ')' block
"dip" delete inner paragraph
"dap" delete a paragraph
"diB" delete inner '{' '}' block
"daB" delete a '{' '}' block
因此,删除一个句子是das
,删除一段落是dap
。
如果您想从J
开始删除直到包括.
,请从J
开始使用df.
如果您想要删除这两行,则使用2dd
另一个选项(不确定在游戏中是否有效)是删除句号及其之前的内容:
d/\./e
在使用删除命令后,如果要使用类似于此的搜索模式,则必须转义句点。
如果您只限于单行,则更简单:
df.
Vim 的语法为 [数字] [操作符/命令] [动作或文本对象]
因此在这个例子中,您可以使用: 2dd
D
。 - kevin