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.
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
HTH,
Gary
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---