-
-
Save PeterRincker/08edd3ea980e778d3986 to your computer and use it in GitHub Desktop.
Revisions
-
PeterRincker revised this gist
Sep 10, 2018 . 1 changed file with 18 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,11 @@ " Repeat change with `.` (jumps to next match). " Can also visually select characters and use `C` set match and start a change if exists('g:loaded_quick_replace') || &cp finish endif let g:loaded_quick_replace = 1 function! s:gn_next() augroup gn_next_repeat autocmd! @@ -31,7 +36,17 @@ function! s:match_visual() call setreg('"', reg, type) endfunction onoremap <expr> <SID>(gn-next) <SID>gn_next() onoremap <script> <Plug>(gn-next) <SID>(gn-next) nnoremap <script> <Plug>(quick-replace) :let @/ = '\V\<' . escape(expand('<cword>'), '\') . '\>'<cr>c<SID>(gn-next) nnoremap <script> <Plug>(quick-replace-g*) :let @/ = '\V' . escape(expand('<cword>'), '\')<cr>c<SID>(gn-next) xnoremap <script> <Plug>(quick-replace) :<c-u>call <SID>match_visual()<cr>c<SID>(gn-next) if !hasmapto("<Plug>(quick-replace)", 'n') nmap cm <Plug>(quick-replace) endif if !hasmapto("<Plug>(quick-replace)", 'v') xmap C <Plug>(quick-replace) endif -
PeterRincker revised this gist
May 18, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,10 +25,10 @@ function! s:gn_next() endfunction function! s:match_visual() let [reg, type] = [@@, getregtype('"')] normal! gvy let @/ = '\V' . escape(@@, '\') call setreg('"', reg, type) endfunction onoremap <expr> <Plug>(gn-next) <SID>gn_next() -
PeterRincker revised this gist
May 18, 2018 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ " Quick Replace " Makes *``cgn like workflows faster by automatically moving to next match. Repeat with `.` " " Requires repeat.vim " " Example mappings: " nmap cm <Plug>(quick-replace) @@ -17,6 +18,7 @@ function! s:gn_next() autocmd! autocmd CursorMoved <buffer> \ execute "autocmd! gn_next_repeat" | \ silent! call repeat#set(v:operator . "\<Plug>(gn-next)" . (v:operator == 'c' ? "\<c-a>\<esc>" : '')) | \ normal! n augroup END return "\<esc>:let &hlsearch=&hlsearch\<cr>" . v:operator . "gn" -
PeterRincker revised this gist
May 18, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,9 @@ " " mnemonic: cm for change matches " " Execute `cmfoo` on a word. Your cursor will then move to the next word after the change. " Repeat change with `.` (jumps to next match). " Can also visually select characters and use `C` set match and start a change function! s:gn_next() augroup gn_next_repeat -
PeterRincker revised this gist
May 18, 2018 . 1 changed file with 15 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,22 @@ " Quick Replace " Makes *``cgn like workflows faster by automatically moving to next match " Repeat with `.` " " Example mappings: " nmap cm <Plug>(quick-replace) " xmap C <Plug>(quick-replace) " " mnemonic: cm for change matches " " The execute `cmfoo<esc>` on a word. Your cursor will then move to the next word. " Repeat change with `.` " Can also visually select characters and use `C` to start changes function! s:gn_next() augroup gn_next_repeat autocmd! autocmd CursorMoved <buffer> \ execute "autocmd! gn_next_repeat" | \ normal! n augroup END return "\<esc>:let &hlsearch=&hlsearch\<cr>" . v:operator . "gn" @@ -19,7 +32,4 @@ endfunction onoremap <expr> <Plug>(gn-next) <SID>gn_next() nmap <Plug>(quick-replace) :let @/ = '\V\<' . escape(expand('<cword>'), '\') . '\>'<cr>c<Plug>(gn-next) xmap <Plug>(quick-replace) :<c-u>call <SID>match_visual()<cr>c<Plug>(gn-next) -
PeterRincker renamed this gist
Dec 15, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
PeterRincker revised this gist
Dec 14, 2014 . 1 changed file with 20 additions and 39 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,44 +1,25 @@ function! s:gn_next() augroup gn_next_repeat autocmd! autocmd CursorMoved <buffer> \ execute "autocmd! gn_next_repeat" | \ silent! call repeat#set(v:operator . "\<Plug>(gn-next)" . (v:operator == 'c' ? "\<c-a>\<esc>" : '')) | \ normal! n augroup END return "\<esc>:let &hlsearch=&hlsearch\<cr>" . v:operator . "gn" endfunction function! s:match_visual() let reg = @@ normal! gvy let @/ = '\V' . escape(@@, '\') let @@ = reg endfunction onoremap <expr> <Plug>(gn-next) <SID>gn_next() nmap <Plug>(quick-replace) :let @/ = '\V\<' . escape(expand('<cword>'), '\') . '\>'<cr>c<Plug>(gn-next) xmap <Plug>(quick-replace) :<c-u>call <SID>match_visual()<cr>c<Plug>(gn-next) nmap <leader>r <Plug>(quick-replace) xmap <leader>r <Plug>(quick-replace) -
orlp created this gist
Dec 13, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ " quick replace occurences let g:should_inject_replace_occurences = 0 function! MoveToNext() if g:should_inject_replace_occurences call feedkeys("n") call repeat#set("\<Plug>ReplaceOccurences") endif let g:should_inject_replace_occurences = 0 endfunction augroup auto_move_to_next autocmd! InsertLeave * :call MoveToNext() augroup END nmap <silent> <Plug>ReplaceOccurences :call ReplaceOccurence()<CR> nmap <silent> <Leader>r :let @/ = '\C\<'.expand('<cword>').'\>'<CR> \:set hlsearch<CR>:let g:should_inject_replace_occurences=1<CR>cgn vmap <silent> <Leader>r :<C-U> \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR> \gvy:let @/ = substitute( \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR>:set hlsearch<CR>:let g:should_inject_replace_occurences=1<CR> \gV:call setreg('"', old_reg, old_regtype)<CR>cgn function! ReplaceOccurence() " check if we are on top of an occurence let l:winview = winsaveview() let l:save_reg = getreg('"') let l:save_regmode = getregtype('"') let [l:lnum_cur, l:col_cur] = getpos(".")[1:2] normal! ygn let [l:lnum1, l:col1] = getpos("'[")[1:2] let [l:lnum2, l:col2] = getpos("']")[1:2] call setreg('"', l:save_reg, l:save_regmode) call winrestview(winview) " if we are on top of an occurence, replace it if l:lnum_cur >= l:lnum1 && l:lnum_cur <= l:lnum2 && l:col_cur >= l:col1 && l:col_cur <= l:col2 exe "normal! cgn\<c-a>\<esc>" endif call feedkeys("n") call repeat#set("\<Plug>ReplaceOccurences") endfunction