Guest User

Untitled

a guest
Jun 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. "---------------------------------------
  2. " Replace
  3.  
  4. set report=0
  5.  
  6. xnoremap S <Nop>
  7.  
  8. " replace the user input in the current line
  9. nnoremap s :<C-u>s//g "<Left><Left><Left><Left>
  10. " replace the cword in the current line
  11. nnoremap ,ls :<C-u>s/\<<C-r>=expand('<cword>')<CR>\>//g "<Left><Left><Left><Left>
  12. nnoremap ,lS :<C-u>s/<C-r>=expand('<cword>')<CR>//g "<Left><Left><Left><Left>
  13. " replace the selection in the current line
  14. xnoremap ,ls "vy:s/\<<C-r>=<SID>reg_v_value()<CR>\>//g "<Left><Left><Left><Left>
  15. xnoremap ,lS "vy:s/<C-r>=<SID>reg_v_value()<CR>//g "<Left><Left><Left><Left>
  16.  
  17. " replace the user input in the current buffer
  18. nnoremap S :<C-u>%s//g "<Left><Left><Left><Left>
  19. " replace the cword in the current buffer
  20. nnoremap ,s :<C-u>%s/\<<C-r>=expand('<cword>')<CR>\>//g "<Left><Left><Left><Left>
  21. nnoremap ,S :<C-u>%s/<C-r>=expand('<cword>')<CR>//g "<Left><Left><Left><Left>
  22. " replace the selection in the current buffer
  23. xnoremap ,s "vy:%s/\<<C-r>=<SID>reg_v_value()<CR>\>//g "<Left><Left><Left><Left>
  24. xnoremap ,S "vy:%s/<C-r>=<SID>reg_v_value()<CR>//g "<Left><Left><Left><Left>
  25.  
  26. " replace the user input in the selection
  27. xnoremap s :s//g "<Left><Left><Left><Left>
  28. " replace the yanted text in the selection
  29. xnoremap ,vy :s/\<<C-r>=@"<CR>\>//g "<Left><Left><Left><Left>
  30. xnoremap ,vY :s/<C-r>=@"<CR>//g "<Left><Left><Left><Left>
  31.  
  32. " replace the user input in the last selected
  33. nnoremap ,vv :<C-u>%s/\%V/g "<Left><Left><Left><Left>
  34. " replace the cword in the last selected
  35. nnoremap ,vs :<C-u>%s/\%V\<<C-r>=expand('<cword>')<CR>\>//g "<Left><Left><Left><Left>
  36. nnoremap ,vS :<C-u>%s/\%V<C-r>=expand('<cword>')<CR>//g "<Left><Left><Left><Left>
  37. " replace the yanted text in the last selected
  38. nnoremap ,vy :<C-u>%s/\%V\<<C-r>=@"<CR>\>//g "<Left><Left><Left><Left>
  39. nnoremap ,vY :<C-u>%s/\%V<C-r>=@"<CR>//g "<Left><Left><Left><Left>
  40.  
  41. " replace the user input in buffers
  42. nnoremap <Leader>: :<C-u>%bufdo s//g "<Left><Left><Left><Left>
  43. " replace the cword in buffers
  44. nnoremap <Leader>s :<C-u>bufdo %s/\<<C-r>=expand('<cword>')<CR>\>//g "<Left><Left><Left><Left>
  45. nnoremap <Leader>S :<C-u>bufdo %s/<C-r>=expand('<cword>')<CR>//g "<Left><Left><Left><Left>
  46. " replace the selection in buffers
  47. xnoremap <Leader>s "vy:bufdo %s/\<<C-r>=<SID>reg_v_value()<CR>\>//g "<Left><Left><Left><Left>
  48. xnoremap <Leader>S "vy:bufdo %s/<C-r>=<SID>reg_v_value()<CR>//g "<Left><Left><Left><Left>
  49.  
  50. function! s:reg_v_value()
  51. return substitute(s:escape_regexp(@v), "\n", '\\n', 'g')
  52. endfunction
  53. function! s:escape_regexp(str)
  54. return escape(a:str, '^$[].*\~' . '/')
  55. endfunction
Add Comment
Please, Sign In to add comment