Re: Opening files in a certain pattern

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern

Manas Gupta
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?

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

Thanks
--
Manas
CSAM Undergraduate | 2022
IIIT-Delhi, India

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727212604.gwjniqrrvsk6ipd3%40nitro-5.
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern

Gary Johnson-4
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727220849.GC7280%40phoenix.
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern

Manas Gupta
On Mon, Jul 27, 2020 at 03:08:49PM -0700, Gary Johnson wrote:

> 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
>
That is the idea which I was thinking but opening other windows (after
the first one) is giving me troubles.

> > 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.
>
That's right. Also the above command actually opens an empty buffer also.

--
Manas
CSAM Undergraduate | 2022
IIIT-Delhi, India

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727225741.4l6so2wi27upohf3%40nitro-5.
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern

Gary Johnson-4
On 2020-07-28, Manas wrote:

> On Mon, Jul 27, 2020 at 03:08:49PM -0700, Gary Johnson wrote:
> > 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
> >
> That is the idea which I was thinking but opening other windows (after
> the first one) is giving me troubles.

If it's still giving you troubles, you could post here what you have
and we could perhaps find the problem.  If you do that, please be
specific about what you mean by giving you troubles.

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727231905.GD7280%40phoenix.
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern

Tim Chase
In reply to this post by Manas Gupta
On 2020-07-28 02:56, 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?
>
> 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).

You might try something like this:

$ vim -p -c 'set tabpagemax=50' -c 'tabdo exec "vsp ".substitute(substitute(expand("%"),"dir1", "dir2", ""), "/L", "/A", "")' dir1/*

(there's a space after the "vsp" in case mail between here and there
decides to eat it)

By default 'tabpagemax' is 10, so you don't need to change that to
50 if you have 10 or fewer files.  Just set it to the number of files
you have.  The "-p" then opens each dir1/L*.md file in its own tab
(they're specified on the command-line).  It then iterates over each
of those tabs (tabdo), transforms the current filename into its mate's
filename (s/dir1/dir2/ and s@/L@/A@) and builds an command to
vertically split (vsp) as a string, and then :exec's it to do the
actual vertical split in each tab.

-tim




--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727183201.41f492e8%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern

Manas Gupta
In reply to this post by Gary Johnson-4
On Mon, Jul 27, 2020 at 04:19:06PM -0700, Gary Johnson wrote:

> On 2020-07-28, Manas wrote:
> > On Mon, Jul 27, 2020 at 03:08:49PM -0700, Gary Johnson wrote:
> > > 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
> > >
> > That is the idea which I was thinking but opening other windows (after
> > the first one) is giving me troubles.
>
> If it's still giving you troubles, you could post here what you have
> and we could perhaps find the problem.  If you do that, please be
> specific about what you mean by giving you troubles.
>
I found `:tabl` which will take me to last tab. So I come up with
opening first 2 panes in starting window as:

$ vim -O2 dir1/L1.md dir2/A1.md

And for opening next 2 panes in new tab after the first tab, first I
opened one file using tab sp and then going to that tab using tabl,
and then vertical splitting second file from dir2. The final command
looked like this:

$ vim -O2 dir1/L1.md dir2/A1.md -c "tab sp dir1/L2.md" -c "tabl" -c "vsp
dir2/A2.md"

It works for me. And I can generate that command in shell script.

Can there be some improvement upon this?

--
Manas
CSAM Undergraduate | 2022
IIIT-Delhi, India

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727233330.wljctxf6fisagkmw%40nitro-5.
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern

Manas Gupta
In reply to this post by Tim Chase
On Mon, Jul 27, 2020 at 06:32:01PM -0500, Tim Chase wrote:

> You might try something like this:
>
> $ vim -p -c 'set tabpagemax=50' -c 'tabdo exec "vsp ".substitute(substitute(expand("%"),"dir1", "dir2", ""), "/L", "/A", "")' dir1/*
>
> (there's a space after the "vsp" in case mail between here and there
> decides to eat it)
>
> By default 'tabpagemax' is 10, so you don't need to change that to
> 50 if you have 10 or fewer files.  Just set it to the number of files
> you have.  The "-p" then opens each dir1/L*.md file in its own tab
> (they're specified on the command-line).  It then iterates over each
> of those tabs (tabdo), transforms the current filename into its mate's
> filename (s/dir1/dir2/ and s@/L@/A@) and builds an command to
> vertically split (vsp) as a string, and then :exec's it to do the
> actual vertical split in each tab.
>
> -tim
>
I am sorry, I missed your mail by a minute. That command works
beautifully. I tried it on my directory structure and works.

Thanks everyone for help!
--
Manas
CSAM Undergraduate | 2022
IIIT-Delhi, India

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727234153.o2vqs3sg3ilqef62%40nitro-5.
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern [follow-up]

Tim Chase
In reply to this post by Tim Chase
On 2020-07-27 18:32, Tim Chase wrote:
> You might try something like this:
>
> $ vim -p -c 'set tabpagemax=50' -c 'tabdo exec "vsp
> ".substitute(substitute(expand("%"),"dir1", "dir2", ""), "/L",
> "/A", "")' dir1/*

Apparently the "tabpagemax" doesn't get set until after Vim has
opened the args in each tab, so this doesn't work for n>10.  So you
have to do the splitting after changing 'tabpagemax'.  I had better
luck with this

$ vim -c 'set tabpagemax=50' -c 'args dir1/*' -c 'argdo tabe %' -c 'tabdo exec "vsp ".substitute(substitute(expand("%"),"dir1", "dir2", ""), "/L", "/A", "")'

It does open one extra window, but seems to work better than the
previous one.

-tim




--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200727185002.67fa0cf9%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

Re: Opening files in a certain pattern [follow-up]

Manas Gupta
On Mon, Jul 27, 2020 at 06:50:02PM -0500, Tim Chase wrote:

> On 2020-07-27 18:32, Tim Chase wrote:
> > You might try something like this:
> >
> > $ vim -p -c 'set tabpagemax=50' -c 'tabdo exec "vsp
> > ".substitute(substitute(expand("%"),"dir1", "dir2", ""), "/L",
> > "/A", "")' dir1/*
>
> Apparently the "tabpagemax" doesn't get set until after Vim has
> opened the args in each tab, so this doesn't work for n>10.  So you
> have to do the splitting after changing 'tabpagemax'.  I had better
> luck with this
>
> $ vim -c 'set tabpagemax=50' -c 'args dir1/*' -c 'argdo tabe %' -c 'tabdo exec "vsp ".substitute(substitute(expand("%"),"dir1", "dir2", ""), "/L", "/A", "")'
>
> It does open one extra window, but seems to work better than the
> previous one.
>
Can we use `--cmd` instead of `-c` as according to manpage:
--cmd   Like using "-c", but the command is executed just before processing any vimrc file.

--
Manas
CSAM Undergraduate | 2022
IIIT-Delhi, India

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200728001231.j7yaco7c3u4nypg7%40nitro-5.