0

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.

Wolfgang R.
  • 333
  • 1
  • 2
  • 10
  • not really sure, vim's tag handling allows precisely this, but you'd need to generate the tags for the key file somehow - which may or may not be more difficult than just pressing `*` with cursor on the key in the left file, switching to the right one and hitting `n`. – Michail Mar 08 '19 at 12:26
  • I intend to toggle quite quick through the list of the first view. A focus switch to the second view will be too slow for my workflow. – Wolfgang R. Mar 08 '19 at 20:12
  • By the way the list of the first view is from a high speed trace session. The lines have an identifier key which can be looked up back to the source code. Stepping through the trace in the first view shall show the related line of the source code within the second view. – Wolfgang R. Mar 08 '19 at 20:19
  • 1
    Oh, if your source is not an arbitrary format, but a language supported by some tags-generating program, then tags is the way to go. If the source itself is static, you can simply generate them beforehand. If not, some autocommand trickery may be required, or maybe a plugin. Also, I apologize for the confusion, in the first comment it should've been "generate the tags for the second file", keys file is mighty irrelevant here. – Michail Mar 08 '19 at 20:31
  • thanks a lot. I don't know this tag handling business but it seems to be the pointer I was looking for. – Wolfgang R. Mar 08 '19 at 20:38
  • `:help tags` gives a good overview of vim's capabilities in this regard, and also mentions some programs for generating the tags (but note that Exuberant Ctags are no longer maintained - still awesome, but newer languages' support may be missing). – Michail Mar 08 '19 at 20:45
  • Seems to be the core part I have to use. To get the workflow mentioned above it has to be embedded into a script to be triggered by selecting a new row within the first view. – Wolfgang R. Mar 08 '19 at 21:02

1 Answers1

0

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>.

Doktor OSwaldo
  • 5,732
  • 20
  • 41
  • Sorry for responding late on this. But I've started yesterday and had to go throughthe basics. Thesesteps I was looking for gave me some help. For me the following mapping is doing the job (slightly different from my request) :nnoremap * :let @/=expand("")wincmd wnormal n :nnoremap ö :let @/=expand("")wincmd wnormal j – Wolfgang R. Mar 15 '19 at 17:29
  • No problem, I seem to have caused a lot of learning and fiddling around with vim, which is great. Wish everybody would learn from general solutions and hints and then work out the specific solution themself. However just wanted to point out, you have to remember, that this changes the register `a`! and it will overwrite anything in it. That is not inherently bad, but should be remembered (and you may want to take another register, something like `k` (most users tend to use the registers around the key `q` most frequently, at least I do)). – Doktor OSwaldo Mar 18 '19 at 06:50
  • If you want to refine that someday, you could write a vimscript function and use a buffer local variable. – Doktor OSwaldo Mar 18 '19 at 06:51