Created
October 14, 2010 03:28
-
-
Save h1mesuke/625511 to your computer and use it in GitHub Desktop.
Vim - My vimrc snippet for replacing texts; ver.2
This file contains 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 characters
"--------------------------------------- | |
" Replace | |
set report=0 | |
xnoremap S <Nop> | |
" replace the user input in the current line | |
nnoremap s :<C-u>s//g "<Left><Left><Left><Left> | |
" replace the cword in the current line | |
nnoremap ,ls :<C-u>s/\<<C-r>=expand('<cword>')<CR>\>//g "<Left><Left><Left><Left> | |
nnoremap ,lS :<C-u>s/<C-r>=expand('<cword>')<CR>//g "<Left><Left><Left><Left> | |
" replace the selection in the current line | |
xnoremap ,ls "vy:s/\<<C-r>=<SID>reg_v_value()<CR>\>//g "<Left><Left><Left><Left> | |
xnoremap ,lS "vy:s/<C-r>=<SID>reg_v_value()<CR>//g "<Left><Left><Left><Left> | |
" replace the user input in the current buffer | |
nnoremap S :<C-u>%s//g "<Left><Left><Left><Left> | |
" replace the cword in the current buffer | |
nnoremap ,s :<C-u>%s/\<<C-r>=expand('<cword>')<CR>\>//g "<Left><Left><Left><Left> | |
nnoremap ,S :<C-u>%s/<C-r>=expand('<cword>')<CR>//g "<Left><Left><Left><Left> | |
" replace the selection in the current buffer | |
xnoremap ,s "vy:%s/\<<C-r>=<SID>reg_v_value()<CR>\>//g "<Left><Left><Left><Left> | |
xnoremap ,S "vy:%s/<C-r>=<SID>reg_v_value()<CR>//g "<Left><Left><Left><Left> | |
" replace the user input in the selection | |
xnoremap s :s//g "<Left><Left><Left><Left> | |
" replace the yanted text in the selection | |
xnoremap ,vy :s/\<<C-r>=@"<CR>\>//g "<Left><Left><Left><Left> | |
xnoremap ,vY :s/<C-r>=@"<CR>//g "<Left><Left><Left><Left> | |
" replace the user input in the last selected | |
nnoremap ,vv :<C-u>%s/\%V/g "<Left><Left><Left><Left> | |
" replace the cword in the last selected | |
nnoremap ,vs :<C-u>%s/\%V\<<C-r>=expand('<cword>')<CR>\>//g "<Left><Left><Left><Left> | |
nnoremap ,vS :<C-u>%s/\%V<C-r>=expand('<cword>')<CR>//g "<Left><Left><Left><Left> | |
" replace the yanted text in the last selected | |
nnoremap ,vy :<C-u>%s/\%V\<<C-r>=@"<CR>\>//g "<Left><Left><Left><Left> | |
nnoremap ,vY :<C-u>%s/\%V<C-r>=@"<CR>//g "<Left><Left><Left><Left> | |
" replace the user input in buffers | |
nnoremap <Leader>: :<C-u>%bufdo s//g "<Left><Left><Left><Left> | |
" replace the cword in buffers | |
nnoremap <Leader>s :<C-u>bufdo %s/\<<C-r>=expand('<cword>')<CR>\>//g "<Left><Left><Left><Left> | |
nnoremap <Leader>S :<C-u>bufdo %s/<C-r>=expand('<cword>')<CR>//g "<Left><Left><Left><Left> | |
" replace the selection in buffers | |
xnoremap <Leader>s "vy:bufdo %s/\<<C-r>=<SID>reg_v_value()<CR>\>//g "<Left><Left><Left><Left> | |
xnoremap <Leader>S "vy:bufdo %s/<C-r>=<SID>reg_v_value()<CR>//g "<Left><Left><Left><Left> | |
function! s:reg_v_value() | |
return substitute(s:escape_regexp(@v), "\n", '\\n', 'g') | |
endfunction | |
function! s:escape_regexp(str) | |
return escape(a:str, '^$[].*\~' . '/') | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment