" ----- put these lines in your 'vimrc' or ':source' them ------- [Vim5.3] --- " Function: Perform an Ex command on a visual highlighted block (CTRL-V). " Usage: Mark visual block (CTRL-V), press ':B ' and enter an Ex command " [cmd]. On the command-line the visual range is automatically " inserted, ie. ":'<,'>B [cmd]" is displayed there (as usual). " Command-line completion is supported for Ex commands. " Notes: There must be a space before the '!' when invoking external shell " commands, eg. ':B !sort'. Otherwise an error is reported. " In regular expressions, the atom '^' specifies the first column " of the marked block. In the same way all other positions count " for the marked area. " Author: Stefan Roemer " commands, eg. ':B !sort'. Otherwise an error is reported. " fu! VisBlockCmd(flag,cmd) let x1=col("'<")|let y1=line("'<") let x2=col("'>")|let y2=line("'>") '>pu_|km|let a=''|let b=''|let l=y1 while l<=y2 let ln=getline(l)|let p1=strpart(ln,0,x1-1)|let p2=strpart(ln,x2,999999999) let a=a.p1."\n"|let b=b.p2."\n"|call setline(l,strpart(ln,x1-1,x2-x1+1)) let l=l+1 endw exe"'<,'>".a:cmd let l=y2-line("'m")|while l>=0|'m-1pu_|let l=l-1|endw|let l=y1 while l<=y2 call setline(l,matchstr(a,"[^\]*").getline(l).matchstr(b,"[^\]*")) let a=substitute(a,".\\{-}\",'','') let b=substitute(b,".\\{-}\",'','') let l=l+1 endw if a:flag==1|exe"'md"|else|exe y2+1.",'md" endif endf " ------------------------------------------------------------------------------ " if more lines than the size of the marked block are inserted, cut them off com! -range -nargs=+ -com=command B call VisBlockCmd(0,'') " keep all lines even if there are additional lines inserted after the block com! -ra -n=+ -com=command C call VisBlockCmd(1,'') " ------------------------------------------------------------------------------ " Function to fill a block with increasing numbers. " For example, selecting the block and typing " :'<,'>I 4 5 " would fill the block with the numbers 4, 9, 14, 19, etc. " The filled numbers are right justified. " Author : Aziz (aziz@freeshell.org) " This uses the macro above. fu! InsNum(start, incr) range let saverep=&report set report=100000 let c = line("'<")*a:incr-a:start let spaces=" " " Find the length of the number required in the last line let maxlen = strlen(a:incr*line("'>")-c) " Right justify it with respect to this length let justifyStr="strpart(\"".spaces."\",0,". \maxlen."-strlen(line(\".\")*".a:incr."-".c."))" let cmd = "g/^/exec(\"s/.*/\".".justifyStr.".". \"(line(\".\")*".a:incr."-".c.").\"/\")" exec("'<,'>B ".cmd) let &report=saverep endf com! -ra -nargs=* Incr call InsNum()