I have two text files, ones is the file I’m currently working, the other contains a list of line numbers. What I would like to do is to highlight lines in the first file where the line number matches the latter one.
E.g.:
File1:
I like eggs
I like meat
I don't like eggplant
My mom likes chocolate
I like chocolate too
File2:
2
4
In this example the those lines should be highlighted:
I like meat
My mom likes chocolate
Thanks!
You can use
readfile()to read in the line numbers, and then convert them into a regular expression that matches those line numbers (e.g.\%42l). The highlighting can be done via:match, ormatchadd().Here’s all this condensed into a custom
:MatchLinesFromFilecommand: