Friday, October 11, 2013

Re: (Vimscript) Move lines that match a patter to the top of buffer?

This is perfect, thanks.

On Friday, October 11, 2013 12:27:57 AM UTC+9, Ben Fritz wrote:
> On Thursday, October 10, 2013 9:13:45 AM UTC-5, Horacio Sanson wrote:
> > I am trying to write a vimscript function that would search all lines that match a certain pattern "^\s*import\s\s*.*;" and move them to the top of the buffer. This is to move all imports in a java file to the top.
> >
> > Even better would be to move all the import line below the package line on the java source file.
> >
> > In the editor I can use this command to get the desired effect:
> >
> > " Moves all import lines to the top
> > v/^\s*import\s\s*.*;/normal ddGp
> >
> > " Moves the pacakge line to the top, above the imports
> > v/^\s*package\s\s*.*;/normal ddGp
> >
> > How to translate that visual command to work in vimscript?
> >
> > regards,
> > Horacio
>
> Move all lines matching "import" to the top of the file:
>
> :g/import/move 0
>
> Move all lines matching "import" to be just after a line containing "package":
>
> :g/import/move /package/
>
> See :help :g, :help :move, http://vim.wikia.com/wiki/Power_of_g

--
--
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.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: