Skip to content

Feature request: Show horizontal context (and one hit per string occurrence) #234

@forthrin

Description

@forthrin

Some times, like when Web authors think it's a good idea to put 5 megabytes of inline JSON objects on a single line in HTML files, it gets difficult to grep/ack sanely for content.

This can be resolved by introducing horizontal context, which snugly centres the desired content on the terminal line. As a related necessity (or possibly a separate option), the mode should show one search hit per occurrence on the line, as illustrated in the example below:

$ ack --horizontal-context FOO
1,40: ... lorem ipsum dolor sit amet FOO consectetur adipiscing vel ...
1,40960: ... erat velit scelerisque in FOO egestas egestas fringilla ...
1,384350: ... vel turpis nunc eget lorem FOO dolor sed viverra dolor ...
43,150: ... diam donec adipiscing tristique FOO risus egestas lorem ...

The form "line,column" can be conveniently fed to editors like nano via the "+" goto syntax.

If the found text itself surpasses terminal width, the following form would be appropriate:

$ ack --horizontal-context "var \w+ = .*;"
1,40960: ... var foo = ["foo": 1, "bar": 2 ... "almost": 999, "finished": 1000]; ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions