如何在 Vim 的多行中间插入文本? [英] How can I insert text in the middle of the line to multiple lines in Vim?

查看:30
本文介绍了如何在 Vim 的多行中间插入文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有十行,我想在这些行中出现的某个单词前添加文本?它不必在行首.

Say I have ten lines and I want to prepend text to some word that occurs in those lines? It does not have to be at the beginning of the line.

来自:

sdfsd   foo sdfsd
sfsd    foo fsdf
sdfsdf  foo  sdfsdf

到:

sdfsd   bar(foo sdfsd
sfsd    bar(foo fsdf
sdfsdf  bar(foo  sdfsdf

是否也有可能不仅在 bar( 前面,而且实际上用 bar(foo) 包围 foo ?

Is it also possible to not only prepend the bar( but actually surround foo with bar(foo)?

我还想要一种将 // 注释附加到多行(C 样式注释)的快速方法.

I would also like a quick way to append // comments to multiple lines (C-style comments).

我使用 Vim/GVim 7.2.

I use Vim/GVim 7.2.

推荐答案

转到第一个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.

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.

这篇关于如何在 Vim 的多行中间插入文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆