Search code examples
vimscriptingvimdiff

vimdiff like view but for key lookup


I'm a simple user of vi. But now I'm looking for a bit more sophisticated solution. What I've in mind should look like a vimdiff view, but it's not about diffs.

My first view has a file open with lines having one 'key' string as part of each line.

The second view is read-only showing another file. This one has each key exactly one time in that file embedded in a line.

The following behaviour I'm looking for

  • navigate the cursor to a new line in file 1

now without any further user activity

  • find the key string within this line

  • search this key within the second view

  • scroll to this line to become the center of view 2

  • highlight line (or key) in view 2

If someone can give me a starting point or what might be available already?

thanks in advance

Wolfgang R.


Solution

  • This should be possible without tags, however you will need a custom function or a macro which does something like that:

    1. search the key in the current line: /key:\s\zs.*\ze\s (this assumes you are searching for the value in a key: value combination).
    2. search for that word *
    3. jump to the next split <c-w>l
    4. jump to occurence n
    5. jump back to previous split <c-w>h
    6. add new line to the end Go

    you can use that:

    :let @a = '/key:\s\zs.*\ze\s^M*^Wln^WhGo
    

    to save it to register a. Important is that ^M has to be entered with <c-v><cr> and ^W has to be entered with <c-v><c-w>.