diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-07-04 19:31:38 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-07-04 19:31:38 +0800 |
| commit | 6d7c95e031bb193e4700a5a9d58e0fa27efe0c30 (patch) | |
| tree | 05e6cbe4eec2bdce2d2c5299afd2fbebed8d0357 /vim/init | |
| parent | 464d830c38d6c11258c60782ef9b4fb9de406957 (diff) | |
Update
Diffstat (limited to 'vim/init')
| -rw-r--r-- | vim/init/keymaps.vim | 34 |
1 files changed, 21 insertions, 13 deletions
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<CR>:pwd<CR> | |||
| 88 | " Switch CDW to root git directory | 88 | " Switch CDW to root git directory |
| 89 | nnoremap cdg :execute 'cd' fnameescape(fnamemodify(finddir('.git', escape(expand('%:p:h'), ' ') . ';'), ':h'))<CR>:pwd<CR> | 89 | nnoremap cdg :execute 'cd' fnameescape(fnamemodify(finddir('.git', escape(expand('%:p:h'), ' ') . ';'), ':h'))<CR>:pwd<CR> |
| 90 | " alias for cd | 90 | " alias for cd |
| 91 | nnoremap cd<space> :cd<space> | 91 | nnoremap cdd :cd<space> |
| 92 | nnoremap cd.. :cd .. <CR>:pwd<CR> | 92 | nnoremap cd.. :cd .. <CR>:pwd<CR> |
| 93 | nnoremap cd... :cd ../.. <CR>:pwd<CR> | 93 | nnoremap cd... :cd ../.. <CR>:pwd<CR> |
| 94 | 94 | ||
| @@ -317,22 +317,30 @@ endfunction | |||
| 317 | 317 | ||
| 318 | command! -nargs=1 -complete=command Redir silent call Redir(<q-args>) | 318 | command! -nargs=1 -complete=command Redir silent call Redir(<q-args>) |
| 319 | nnoremap <leader>rr :Redir<space> | 319 | nnoremap <leader>rr :Redir<space> |
| 320 | |||
| 321 | |||
| 322 | "---------------------------------------------------------------------- | 320 | "---------------------------------------------------------------------- |
| 323 | " QUICK_SUBSTITUTE | 321 | " QUICK_SUBSTITUTE |
| 324 | "---------------------------------------------------------------------- | 322 | " Press <TAB> n times for area, and <CR> for substitute |
| 325 | let g:text_selected = 1 | 323 | let g:search_not_in_register = 1 |
| 326 | function! SelectAreaOrDoSubstitute() | 324 | function! ExpandSelectionForSearch(sep) |
| 327 | if g:text_selected | 325 | if g:search_not_in_register == 1 |
| 328 | call feedkeys("\"sygv/\<C-R>s\<CR>gn") | 326 | " Save current selection to register s, and keep selection |
| 329 | let g:text_selected = 0 | 327 | execute 'norm "sygv' |
| 330 | else | 328 | let g:search_not_in_register = 0 |
| 331 | call feedkeys(":s//\<C-R>//g\<Left>\<Left>") | ||
| 332 | let g:text_selected = 1 | ||
| 333 | endif | 329 | endif |
| 330 | " Use register s to go to next search, counts/total is displayed in | ||
| 331 | " statusline | ||
| 332 | call feedkeys(a:sep.."\<C-R>s"..a:sep.."e\<CR>") | ||
| 333 | endfunction | ||
| 334 | function! SubstituteForSearch() | ||
| 335 | " Apply current for default substitute text | ||
| 336 | call feedkeys(":s//\<C-R>s/g\<Left>\<Left>") | ||
| 334 | endfunction | 337 | endfunction |
| 335 | vnoremap <TAB> <Cmd>call SelectAreaOrDoSubstitute()<CR> | 338 | vnoremap <TAB> <Cmd>call ExpandSelectionForSearch('/')<CR> |
| 339 | vnoremap <S-TAB> <Cmd>call ExpandSelectionForSearch('?')<CR> | ||
| 340 | vnoremap <CR> <Cmd>call SubstituteForSearch()<CR> | ||
| 341 | " When leaving visual mode, resume search_not_in_register | ||
| 342 | autocmd Modechanged [vV\x16]*:* let g:search_not_in_register = 1 | ||
| 343 | |||
| 336 | 344 | ||
| 337 | 345 | ||
| 338 | "---------------------------------------------------------------------- | 346 | "---------------------------------------------------------------------- |