On 2009-09-14, Daniel Fetchinson wrote:
> >> >>> I'm regularly doing :split filename1 followed by :split filename2
> >> >>> followed by :split filename3 and was trying to do :split filename* but
> >> >>> this didn't work. The goal would be to split the window in as many
> >> >>> pieces as the number of files that match filename* and have each of
> >> >>> the matching files in it's own split window.
> >> >>>
> >> >>> Basically I'm trying to automate :split filename1 :split filename2
> >> >>> :split filename3 etc etc.
> >> >>>
> >> >>> Is there a way to do this?
> >> >>
> >> >> You can do
> >> >>
> >> >> :args filename*
> >> >>
> >> >> to set the argument list to that set of files, then
> >> >>
> >> >> :all
> >> >>
> >> >> to open each file in the argument list in a new window.
> >> >
> >> > Wow, this is great, thanks! If I would have known this in the last 10
> >> > years..... :)
> >>
> >> This in itself is pretty cool, but now I'd like to make something even
> >> cooler by hooking up a custom function to do this. This is where I'm
> >> currently failing. What I'd like to see is when I type
> >>
> >> :msplit filename*
> >>
> >> then this should be equivalent to
> >>
> >> :args filename*
> >> :all
> >>
> >> where of course msplit stands for multiple split. I don't really know
> >> how vim functions work, so far I was always copy-pasting already
> >> working stuff and only modified them for myself. So based on this
> >> limited experience what I tried was
> >>
> >> function! Msplit( expr )
> >> args a:expr
> >> all
> >> endfunction
> >>
> >> but this (maybe trivially) doesn't work. What would be the way to do this?
> >
> > First of all, it would help to know precisely what you mean by
> > "doesn't work". It would also help to know how you got from typing
> > ":msplit filename*" to calling Msplit(). Otherwise we're all left
> > guessing what you might have done and how it might have failed.
>
> Sorry, you are right, I was not clear. So when I define
>
> function! Msplit( expr )
> args a:expr
> all
> endfunction
>
> and then I do either of the following,
>
> (1) :call Msplit( 'filename*' )
> (2) :call Msplit( "filename*" )
> (3) :call Msplit( filename* )
>
> (you can already see that I'm more or less guessing here) then what I get is,
>
> (1) vim opens a new empty file called 'a:expr'
> (2) same as (1)
> (3) vim says 'Invalid expression' and 'Invalid arguments for function Msplit'
>
> So this is what I meant when I said it doesn't work.
Thank you. If we were to pursue putting this in a function, that
would be very helpful.
> > That being said, here's my guess at what went wrong and a possible
> > solution.
> >
> > The string "filename*" is converted to a string of file names by the
> > process of filename expansion. This works only in certain contexts.
> > I don't know what all those contexts are. To make this work in a
> > function, I think you'd either have to use the glob() function in
> > your function to expand a:expr to a set of file names, or use a
> > :command that would expand "filename*" before passing all the
> > resulting names to Msplit().
> >
> > I think it would be easiest to just implement this as a command
> > without the use of a function, like this:
> >
> > command! -nargs=+ Msplit args <args><bar>all
>
> This works wonderfully, thank you very much!
>
> I realize that I'm asking for too much, but just in case somebody
> finds this also useful, let me ask what makes :Msplit and :split
> different from the point of view of Tab-completion? When the command
> :split is followed by a string of characters (filenames) and one
> presses Tab, vim will autocomplete them based on existing file names.
> However in its current form :Msplit doesn't do this, I guess because
> nobody told it to do so :) Is there a way to tell vim "try to
> Tab-autocomplete the arguments of this command"?
I threw that command together without thinking about niceties, but
Hari included that capability in his reply. If you look at
:help command-completion
you'll find the "-complete=file" option and a lot more. If you're
thinking of other things you might do with your own commands, you'll
find lots of good information under
:help user-commands
> Thanks a lot for your help again,
You're welcome.
Regards,
Gary
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---