Am 17.01.2012 16:22, schrieb Charles Campbell:
rail shafigulin wrote:does anybody know if it is possible to specify multiple ranges in vim for a command execution for example: :1,4s/old/new/g - this command will replace old to new in lines 1 to 4 inclusivehowever what if i want to execute this command in multiple places say something like :1,4;10,14;20,24s/old/new/g - i want to do a replacement on lines 1 through 4, 10 through 14, and 20 through 24 does anybody know if it is possible in vim?
Not exactly. Vim doesn't support multiple ranges; however, you can construct regular expressions that often enable the same thing. For your example, consider \%(\%>0l\&\%<5l\)\|\%(\%>9l\&\%<15l\)\|\%(\%>19l\&\%<25l\) so you could couple that with :g/\%(\%>0l\&\%<5l\)\|\%(\%>9l\&\%<15l\)\|\%(\%>19l\&\%<25l\)/somecommand However, it is somewhat awkward to type. I suppose one could write a plugin to simplify the production of such regexps; it would be straightforward. Regards, Chip Campbell
There is such a plugin (although it doesn't create regexps): multiselect : Create multiple selections and operate http://vim.sourceforge.net/scripts/script.php?script_id=953 Select lines Ctrl-Click or Ctrl-Drag or :[range]MSAdd ... Execute command(s): :MSExecCmd s/old/new/ ... Remove all selections: :MSClear -- Andy -- 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
