@@ -205,7 +205,7 @@ function! s:detect_style_file() abort
205
205
endfunction
206
206
207
207
function ! clang_format#format (line1, line2) abort
208
- let args = printf ( ' -lines=%d:%d ' , a: line1 , a: line2 )
208
+ let args = " "
209
209
if ! (g: clang_format #detect_style_file && s: detect_style_file ())
210
210
let args .= printf (' -style=%s ' , s: make_style_options ())
211
211
else
@@ -217,8 +217,7 @@ function! clang_format#format(line1, line2) abort
217
217
endif
218
218
let args .= g: clang_format #extra_args
219
219
let clang_format = printf (' %s %s --' , s: shellescape (g: clang_format #command ), args )
220
- let source = join (getline (1 , ' $' ), " \n " )
221
- return s: system (clang_format, source )
220
+ return s: system (clang_format, join (getline (a: line1 , a: line2 ), " \n " ))
222
221
endfunction
223
222
" }}}
224
223
@@ -238,8 +237,12 @@ function! clang_format#replace(line1, line2, ...) abort
238
237
try
239
238
let formatted = clang_format#format (a: line1 , a: line2 )
240
239
if s: success (formatted)
240
+ let indent = indent (a: line1 ) / shiftwidth ()
241
+ silent exe a: line1 .' ,' a: line2 .' delete _'
242
+
241
243
call setreg (' g' , formatted, ' V' )
242
- silent keepjumps normal ! gg0VG" gp
244
+ silent put ! g
245
+ silent exe " '[,']" .repeat (' >' , indent )
243
246
else
244
247
call s: error_message (formatted)
245
248
endif
0 commit comments