From 8ffd4df1fa7a2a7e0577c54ff6f9af0610d1d282 Mon Sep 17 00:00:00 2001 From: druckdev Date: Thu, 20 Jan 2022 16:05:47 +0100 Subject: [PATCH] vim:keys: Add insert mappings for better undo The bigger `inoremap ...` binding is taken from the help page `:help i_ctrl-g_u`. --- .config/vim/vimrc.d/40-keys.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.config/vim/vimrc.d/40-keys.vim b/.config/vim/vimrc.d/40-keys.vim index a3aa9e5..5f5003b 100644 --- a/.config/vim/vimrc.d/40-keys.vim +++ b/.config/vim/vimrc.d/40-keys.vim @@ -130,3 +130,22 @@ inoremap :m .+1==gi " Fix & command to also use last flags nnoremap & :&& xnoremap & :&& + +" see :help i_ctrl-g_u +" Do not break undo sequence when using the arrow keys or home and end in insert +" mode +inoremap U +inoremap U +inoremap col('.') == match(getline('.'), '\S') + 1 ? + \ repeat('U', col('.') - 1) : + \ (col('.') < match(getline('.'), '\S') ? + \ repeat('U', match(getline('.'), '\S') + 0) : + \ repeat('U', col('.') - 1 - match(getline('.'), '\S'))) +inoremap repeat('U', col('$') - col('.')) +" Make insert-mode texts repeatable by `.` with the closing parentheses at the +" right position +inoremap ( ()U +" break undo sequence with every space and newline, making insert mode changes +" revertible in smaller chunks +inoremap u +inoremap u