且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Vim 中将行中间的文本插入多行?

更新时间:2023-01-16 15:17:17

转到第一个foo,按Ctrl-v进入视觉块模式并按下直到所有带有 foo 的行都被标记.然后按 Shift-i 插入(块的开头).完成后按Esc,插入的字符将添加到标记块左侧的每一行.

Go to the first foo, press Ctrl-v to enter visual block mode and press down until all the lines with foo are marked. Then press Shift-i to insert at the beginning (of the block). When you are finished and press Esc, the inserted characters will be added to each line at the left of the marked block.

要在末尾插入,再次按 Ctrl-v,向上/向下移动以标记所有受影响的行,然后按 End$ 将选择范围扩展到行尾.现在您可以按 Shift-a 附加到所有行的末尾,就像之前使用 Shift-i一样kbd>.

To insert at the end, press again Ctrl-v, move up/down to mark all affected lines and then press End or $ to extend the selection until the end of the lines. Now you can press Shift-a to append at the end of all the lines, just like previously with Shift-i.

视觉选择也可以通过正常的移动命令来完成.因此,要在 C 中注释整个块,您可以移动到左大括号并键入 Ctrl-v % Shift-i // Esc.

The visual selection can also be done with normal movement commands. So to comment a whole block in C you could move to the opening brace and type Ctrl-v % Shift-i // Esc.