I have the following in an XML file:
我在XML文件中有以下内容:
<TypeDef name="a">
<ArrayType high="14" low="0">
<UndefType type="node">
</UndefType>
</ArrayType>
</TypeDef>
And I want to copy this entry. Normally I'd go to the first line, enter Line-Visual mode using V
, go down to the last line, yank and paste.
我想复制这个条目。通常我会转到第一行,使用V进入Line-Visual模式,转到最后一行,猛拉并粘贴。
How can I copy the entire entry without looking for the end of the entry myself?
如何在不查找条目结尾的情况下复制整个条目?
2 个解决方案
#1
2
In addition to Nathan's answer you might want to check out matchit.vim ... If you have a newer install you probably have it
除了Nathan的回答你可能想看看matchit.vim ...如果你有一个更新的安装你可能有它
http://www.vim.org/scripts/script.php?script_id=39
http://www.vim.org/scripts/script.php?script_id=39
matchit extends vim's % (find matching bracket) to cover xml/html tags and more. So for your solution the action would be from the beginning tag
matchit扩展了vim的%(找到匹配的括号)来覆盖xml / html标签等等。因此,对于您的解决方案,操作将来自开始标记
V%y
matchit is of course very useful for general navigating purposes.
matchit对于一般导航目的当然非常有用。
#2
6
The solution I learned today (thanks to CMS who answered this question) is to use VIM's text object motions.
我今天学到的解决方案(感谢CMS回答了这个问题)是使用VIM的文本对象动作。
Put the cursor in the entry to copy, and type the following in command mode: yat
:
将光标放在要复制的条目中,然后在命令模式下键入以下内容:yat:
-
y
yanks according to the following movement. - y根据以下动作猛拉。
-
at
selects the current tag. - at选择当前标签。
Note that if the cursor is inside the "ArrayType" tag, then that's what will be yanked.
Also note that this won't yank the entire lines. Only from the opening brace of the opening tag to the closing brace of the closing tag. This may cause alignment issues if you're not careful.
请注意,如果光标位于“ArrayType”标记内,那么将会被拉出。另请注意,这不会拉扯整条线。仅从开口标签的开口支撑到关闭标签的闭合支撑。如果您不小心,这可能会导致对齐问题。
One way to get around this is by pasting with :put
instead of just p
, like this: yat:put
.
Note that this won't preserve indentation, because the XML entry wasn't yanked as a whole line.
解决这个问题的一种方法是粘贴:put而不是p,就像这样:yat:put。请注意,这不会保留缩进,因为XML条目不会作为整行被拉动。
Another way to do it is: vatVy
:
另一种方法是:vatVy:
-
v
enters Visual Mode. - v进入可视模式。
-
at
is as above. - 如上所述。
-
V
switches to Line Visual mode and selects the entire line. - V切换到Line Visual模式并选择整行。
-
y
yanks the selection. - y猛烈挑选。
#1
2
In addition to Nathan's answer you might want to check out matchit.vim ... If you have a newer install you probably have it
除了Nathan的回答你可能想看看matchit.vim ...如果你有一个更新的安装你可能有它
http://www.vim.org/scripts/script.php?script_id=39
http://www.vim.org/scripts/script.php?script_id=39
matchit extends vim's % (find matching bracket) to cover xml/html tags and more. So for your solution the action would be from the beginning tag
matchit扩展了vim的%(找到匹配的括号)来覆盖xml / html标签等等。因此,对于您的解决方案,操作将来自开始标记
V%y
matchit is of course very useful for general navigating purposes.
matchit对于一般导航目的当然非常有用。
#2
6
The solution I learned today (thanks to CMS who answered this question) is to use VIM's text object motions.
我今天学到的解决方案(感谢CMS回答了这个问题)是使用VIM的文本对象动作。
Put the cursor in the entry to copy, and type the following in command mode: yat
:
将光标放在要复制的条目中,然后在命令模式下键入以下内容:yat:
-
y
yanks according to the following movement. - y根据以下动作猛拉。
-
at
selects the current tag. - at选择当前标签。
Note that if the cursor is inside the "ArrayType" tag, then that's what will be yanked.
Also note that this won't yank the entire lines. Only from the opening brace of the opening tag to the closing brace of the closing tag. This may cause alignment issues if you're not careful.
请注意,如果光标位于“ArrayType”标记内,那么将会被拉出。另请注意,这不会拉扯整条线。仅从开口标签的开口支撑到关闭标签的闭合支撑。如果您不小心,这可能会导致对齐问题。
One way to get around this is by pasting with :put
instead of just p
, like this: yat:put
.
Note that this won't preserve indentation, because the XML entry wasn't yanked as a whole line.
解决这个问题的一种方法是粘贴:put而不是p,就像这样:yat:put。请注意,这不会保留缩进,因为XML条目不会作为整行被拉动。
Another way to do it is: vatVy
:
另一种方法是:vatVy:
-
v
enters Visual Mode. - v进入可视模式。
-
at
is as above. - 如上所述。
-
V
switches to Line Visual mode and selects the entire line. - V切换到Line Visual模式并选择整行。
-
y
yanks the selection. - y猛烈挑选。