From 6d7c95e031bb193e4700a5a9d58e0fa27efe0c30 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 4 Jul 2024 19:31:38 +0800 Subject: Update --- snippets/vim_autoevent_for_visual_mode | 5 +++++ vim/init/keymaps.vim | 34 +++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 snippets/vim_autoevent_for_visual_mode diff --git a/snippets/vim_autoevent_for_visual_mode b/snippets/vim_autoevent_for_visual_mode new file mode 100644 index 0000000..998a584 --- /dev/null +++ b/snippets/vim_autoevent_for_visual_mode @@ -0,0 +1,5 @@ +augroup VisualEvent + autocmd! + autocmd ModeChanged *:[vV\x16]* :echom 'VisualEnter' + autocmd Modechanged [vV\x16]*:* :echom 'VisualLeave' +augroup END diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index 5441f32..eca23f9 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim @@ -88,7 +88,7 @@ nnoremap cd :cd %:p:h:pwd " Switch CDW to root git directory nnoremap cdg :execute 'cd' fnameescape(fnamemodify(finddir('.git', escape(expand('%:p:h'), ' ') . ';'), ':h')):pwd " alias for cd -nnoremap cd :cd +nnoremap cdd :cd nnoremap cd.. :cd .. :pwd nnoremap cd... :cd ../.. :pwd @@ -317,22 +317,30 @@ endfunction command! -nargs=1 -complete=command Redir silent call Redir() nnoremap rr :Redir - - "---------------------------------------------------------------------- " QUICK_SUBSTITUTE -"---------------------------------------------------------------------- -let g:text_selected = 1 -function! SelectAreaOrDoSubstitute() - if g:text_selected - call feedkeys("\"sygv/\s\gn") - let g:text_selected = 0 - else - call feedkeys(":s//\//g\\") - let g:text_selected = 1 +" Press n times for area, and for substitute +let g:search_not_in_register = 1 +function! ExpandSelectionForSearch(sep) + if g:search_not_in_register == 1 + " Save current selection to register s, and keep selection + execute 'norm "sygv' + let g:search_not_in_register = 0 endif + " Use register s to go to next search, counts/total is displayed in + " statusline + call feedkeys(a:sep.."\s"..a:sep.."e\") +endfunction +function! SubstituteForSearch() + " Apply current for default substitute text + call feedkeys(":s//\s/g\\") endfunction -vnoremap call SelectAreaOrDoSubstitute() +vnoremap call ExpandSelectionForSearch('/') +vnoremap call ExpandSelectionForSearch('?') +vnoremap call SubstituteForSearch() +" When leaving visual mode, resume search_not_in_register +autocmd Modechanged [vV\x16]*:* let g:search_not_in_register = 1 + "---------------------------------------------------------------------- -- cgit v1.2.3-70-g09d2