1

I did my best to find the answer to this; my apologies if I missed it.

Some quick background: I'm looking at the protocol parsers in Bro, specifically those that have been created using BinPAC. In each folder I'm interested in, there are multiple files I want to open, using the naming convention {protocol-name}-protocol.pac, and {protocol-name}-analyzer.pac. The best way to view each protocol's files is side-by-side.

Now, what I want to do is have a separate tab open for each pair. That is, the first tab will have {protocol1}-protocol.pac in one window, and {protocol1}-analyzer.pac in an adjacent window, the second tab will have {protocol2}-protocol.pac in one window, and {protocol2}-analyzer.pac in an adjacent window, and so on.

I'm trying to figure out a way to do the above for all of the relevant folders in one command from the command line. I know how to open all the relevant files in separate tabs, or separate windows, but I can't figure out a way to combine these to get the behavior I want. I could do this manually i.e. open one pair, create a new tab and open another pair etc., but that's obnoxious and repetitive, so I'd much rather do it in one command if possible.

Anyone have any idea how to do this? Or if it's even possible?

hairlessbear
  • 341
  • 3
  • 11
  • Are you always using the exact same set of files? – Zach Aug 22 '14 at 21:29
  • I'm writing a protocol parser of my own, so I've added a new folder with a couple files, but other than that, yes. Why do you ask? – hairlessbear Aug 22 '14 at 21:41
  • 2
    Well I was thinking that you could use sessions to save the layout of your splits, tabs, and files so that you would only have to open it once and then you could just open the session instead of opening each file over again. More on sessions here: http://stackoverflow.com/questions/1642611/how-to-save-a-session-in-vim – Zach Aug 22 '14 at 21:52
  • I think either the session thing or writing vimscript to do this by checking filenames is the best way – Kache Aug 22 '14 at 22:01
  • I didn't know about sessions; that certainly looks like it'll solve my problem. Obviously, it'd be ideal to have a command to run, but in lieu of that, a session will work fine. Thanks! – hairlessbear Aug 22 '14 at 23:34
  • You can pass arbitrary commands to vim when you launch it (`vim -c` or `vim -S`). So yes it is possible. – FDinoff Aug 23 '14 at 00:21
  • I'm glad sessions are sufficient for your needs – Zach Aug 23 '14 at 01:57

1 Answers1

0

It should be possible using --remote-tab option of vim

First start a vim server

     $ gvim --servername MYSERVER &

Now add your protocol files one by one to the vim server, while adding replace the -protocol in the file name to -analyzer and open it in vs[plit] to get the corresponding analyzer file.

     $ find  . -name \*.pac -exec gvim  --servername MYSERVER --remote-tab "+execute 'vs ' . substitute(expand('%:p'), '-protocol', '-analyzer', '')"  {} \;

Refer http://vimdoc.sourceforge.net/htmldoc/remote.html for more details.

Hope this is helpful

siu
  • 312
  • 1
  • 5
  • 10