ajwood
ajwood

Reputation: 19027

Highlight only a portion of a search term in Vim

I'm looking for a way to have vim's search highlighting work on only a part of my search term.

I'm viewing a huge log file of data dumps. It looks something like this: field1: 12345 field2: 12345 field3: 12345 field4: 12345 field5: 12345 ... field1: 11111 field2: 22222 field3: 33333 ... and so on.

I'd like to be able to have all of the fieldX values highlighted for a moment, then quickly switch to highlighting the values for fieldY. Is it possible to search for something like 'field3: \d\d\d\d\d' and have only the number part highlighted?

So in searching for 'my highlight search term' I'd like only 'highlight' to get highlighted.

Thanks,

Andrew

Upvotes: 1

Views: 174

Answers (3)

Nick Knowlson
Nick Knowlson

Reputation: 7416

If I am understanding your question correctly, you can try searching like this:

/field3: \zs\d\d\d\d\d

That will highlight any numbers (and only the numbers) that come after field3:

For quick switching, you could try: /, up-arrow, change field3 to field2.

Is that what you were looking for?

Upvotes: 3

dimba
dimba

Reputation: 27571

Not exactly what you're searching, but running:

:%!column -t

will make your columns more visible

Upvotes: 0

g19fanatic
g19fanatic

Reputation: 10921

well highlight fieldY i'm not sure (a lil bit of a vim noob) but you should be able to just goto the next work by typing w

to get to the next fieldX, type n

this won't highlight fieldy but it will put your cursor at the beginning of that number

Upvotes: 0

Related Questions