VIM - 拉出尴尬文本块的最快方法
我正在使用 VIM 7.1.314,并且想尽快提取下面所示代码中的名称 (chris, robert, ben)
- 我该如何实现这一点?请注意,名称始终对齐(无论用户数量多少)。
user 1: chris (05/04/1984)
user 2: robert (11/12/1991)
user 3: ben (5/25/1993)
另请注意,我正在寻找一个有数百个名称的解决方案,因此可扩展性很重要。
I am using VIM 7.1.314 and would like to yank the names (chris, robert, ben)
in the code shown below as fast as possible - how would I achieve this? Note the names are always aligned (regardless of users number).
user 1: chris (05/04/1984)
user 2: robert (11/12/1991)
user 3: ben (5/25/1993)
Also note, I'm looking for a solution where there is hundreds of names so scalability is important.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一个简单的方法就是求助于外部程序来提供帮助。例如:
这会将整个编辑缓冲区替换为对当前缓冲区的内容运行
awk
命令的结果。然后,您可以将结果复制到另一个文件或其他文件中,u
可以轻松地将原始缓冲区恢复到之前的状态。An easy way to do this is to shell out to an external program to help. For example:
That will replace your entire edit buffer with the results of running that
awk
command on the contents of the current buffer. You can then copy the result to another file or whatever, andu
easily gets your original buffer back to its previous state.鉴于您的名称不会超过 16 个字符,请使用正则表达式搜索和替换在每个名称后添加 16 个空格,然后使用块视觉模式进行复制。首先,执行(在命令行上):
该空白区域为 16 个空格。然后,转到第一个名称的开头并按
Control-V
,然后向右移动 15 个字符并到达名称列表的最后一行,然后按Y
复制,然后复制到目标缓冲区并按P
进行粘贴。Given that your names are not going to be longer than 16 characters, use a regex search and replace to add 16 spaces after each name, then use block visual mode to do the copy. First, do (on the command line):
That blank area is 16 spaces. Then, go to the start of the first name and press
Control-V
, then go 15 characters to the right and to the last line of the list of names and pressY
to copy, then to your destination buffer and pressP
to paste.您可以使用名为 Tabularize 的插件,您可以从 https://github.com/godlygeek/tabular 获取该插件。在您列出的情况下,您可以这样做
,它会将您的文本文件更改为如下所示:
然后您可以简单地使用视觉块来提取文本。这是一个很棒的插件,可以节省大量时间。
You can use a plugin called Tabularize which you can get from https://github.com/godlygeek/tabular. In the case you listed you could do
and it will change your text file to look like this:
Then you can simply use visual block to pull the text. It's a great plugin that saves an incredible amount of time.
这是一个纯 viml 解决方案,保持原始缓冲区不变:
Here is a pure viml solution that leaves the original buffer unchanged:
我会使用宏。
qeq
(清除“e”寄存器)qa03w"Eywjq
(注册提取名称的宏)200000@a
(重复宏)很多时间)然后你的名字就在“e”寄存器中输入“ep”来查看它们!
注意:
yw
不正确,也许是yt(或其他东西,具体取决于名称。:setlazyredraw
可以帮助提高宏性能!I would use macros.
qeq
(to clear the "e" register)qa03w"Eywjq
(to register a macro yanking the name)200000@a
(repeat the macro a lots of time)And then your names are in the "e" register. Type "ep to view them !
Notes :
yw
is not correct, maybe a yt( or something, depending on names.:set lazyredraw
can help with macro performance !