Thursday, October 10, 2013

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

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

--
--
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: