def ReplaceChunksInBuffer(chunks, vim_buffer, locations):
 chunks.sort(key=(lambda chunk: (chunk[u'range'][u'start'][u'line_num'], chunk[u'range'][u'start'][u'column_num'])))
 last_line = (-1)
 line_delta = 0
 for chunk in chunks:
  if (chunk[u'range'][u'start'][u'line_num'] != last_line):
   last_line = chunk[u'range'][u'end'][u'line_num']
   char_delta = 0
  (new_line_delta, new_char_delta) = ReplaceChunk(chunk[u'range'][u'start'], chunk[u'range'][u'end'], chunk[u'replacement_text'], line_delta, char_delta, vim_buffer, locations)
  line_delta += new_line_delta
  char_delta += new_char_delta

def ReplaceChunksInBuffer ( chunks , vim_buffer , locations ) : chunks . sort ( key = ( lambda chunk : ( chunk [ u'range' ] [ u'start' ] [ u'line_num' ] , chunk [ u'range' ] [ u'start' ] [ u'column_num' ] ) ) ) last_line = ( - 1 ) line_delta = 0 for chunk in chunks : if ( chunk [ u'range' ] [ u'start' ] [ u'line_num' ] != last_line ) : last_line = chunk [ u'range' ] [ u'end' ] [ u'line_num' ] char_delta = 0 ( new_line_delta , new_char_delta ) = ReplaceChunk ( chunk [ u'range' ] [ u'start' ] , chunk [ u'range' ] [ u'end' ] , chunk [ u'replacement_text' ] , line_delta , char_delta , vim_buffer , locations ) line_delta += new_line_delta char_delta += new_char_delta
apply changes in |chunks| to the buffer-like object |buffer| .