Monday, July 27, 2020

Re: Opening files in a certain pattern

On 2020-07-28, Manas wrote:
> Hi, I have 2 directories, supposedly dir1 and dir2. And both of them
> contains equal number of files (say n each) which are named in the
> following fashion:
> - In dir1: All files are named as L1.md, L2.md, ...., Ln.md
> - In dir2: All files are named as A1.md, A2.md, ...., An.md
>
> How can I open all of those files such that each window contains two
> vertically-split panes namely, Lx.md and Ax.md (where x is any number)
> and they open in n-different windows?

How's this for a start? The number n here is fixed, but you could
use a while loop instead of the for loop, increment n in each
iteration, and break when one of the files doesn't exist. See
":help filereadable()".

let n = 4
for i in range(n)
exe "tabnew" printf("dir2/A%d.md", i)
exe "vnew" printf("dir1/L%d.md", i)
endfor

> First I was thinking of writing a bash script to open but I got stuck at
> the initial step of finding the appropriate Vim command to open two
> files in a new tab and in vertically-split panes from Ex mode (as I would
> have passed this command using -c flag from my script).

vim -c "tabnew dir2/A${n}.md" -c "vnew dir1/L${n}.md"

That's the general idea, but probably not what you want finally as
it opens only one vim instance and only one pair of files.

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727220849.GC7280%40phoenix.

No comments:

Post a Comment