VIM - The fastest way to capture an awkward text block

I am using VIM 7.1.314 and would like to dig out the names (chris, robert, ben)in the code below as quickly as possible - how would I do this? Note that the names are always aligned (regardless of the number of users).

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 are hundreds of names, so scalability is important.

+3
source share
5 answers

An easy way to do this is to lay out an external program to help. For instance:

:%!awk '{ print $3 }'

awk . , u .

+8

, 16 , , 16 , , . ( ):

:%s/: [^ ]*/&                /

- 16 . Control-V, 15 Y, , P .

+3

Tabularize, https://github.com/godlygeek/tabular.

 :Tabularize /(.*

, :

user 1: chris  (05/04/1984)
user 2: robert (11/12/1991)
user 3: ben    (5/25/1993)

, . , .

+1

viml, :

:let names= []
:g/^user \d/let names+= matchstr(getline('.'), 'user \d\+:\s*\zs\S\+')
:new
:put=names
0

.

  • qeq ( "e" )
  • qa03w"Eywjq ( , )
  • 200000@a ( )

And then your names are in register "e". Enter "ep" to view them!

Notes:

  • Maybe ywwrong, maybe yt (or something depending on the names.
  • :set lazyredraw can help with macro performance!
0
source

Source: https://habr.com/ru/post/1790359/


All Articles