Skip to content

Commit 4475797

Browse files
0xC0FFEErhysd
authored andcommitted
create new undo block for formatting (fix #30) (#55)
* create new undo block for formatting (fix #30) This creates a new undo block to only contain the changes introduced by clang format but still preserves the original cursor position. * fix creation of undo block in visual mode at line 1 * redirect yanked text to black hole register * suppress autocmd events when creating new undo block
1 parent 0961a91 commit 4475797

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

autoload/clang_format.vim

+5
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ function! clang_format#replace(line1, line2)
232232
throw 'fallback'
233233
endif
234234

235+
" Create a new undo block to separate all formatting related
236+
" changes from the last undo block but still preserve original
237+
" cursor position (issue #30).
238+
silent execute "noautocmd normal! ii\<esc>\"_x"
239+
235240
call setreg('g', formatted[i+1:], 'V')
236241
undojoin | silent normal! 2gg"_dG
237242
silent put g

0 commit comments

Comments
 (0)