Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
  2.  
  3. " search for visually hightlighted text
  4. vnoremap <c-f> y<ESC>/<c-r>"<CR>
  5.  
  6. %s//<your-replacement-string>
  7.  
  8. " Escape special characters in a string for exact matching.
  9. " This is useful to copying strings from the file to the search tool
  10. " Based on this - http://peterodding.com/code/vim/profile/autoload/xolox/escape.vim
  11. function! EscapeString (string)
  12. let string=a:string
  13. " Escape regex characters
  14. let string = escape(string, '^$.*/~[]')
  15. " Escape the line endings
  16. let string = substitute(string, 'n', '\n', 'g')
  17. return string
  18. endfunction
  19.  
  20. " Get the current visual block for search and replaces
  21. " This function passed the visual block through a string escape function
  22. " Based on this - https://stackoverflow.com/questions/676600/vim-replace-selected-text/677918#677918
  23. function! GetVisual() range
  24. " Save the current register and clipboard
  25. let reg_save = getreg('"')
  26. let regtype_save = getregtype('"')
  27. let cb_save = &clipboard
  28. set clipboard&
  29.  
  30. " Put the current visual selection in the " register
  31. normal! ""gvy
  32. let selection = getreg('"')
  33.  
  34. " Put the saved registers and clipboards back
  35. call setreg('"', reg_save, regtype_save)
  36. let &clipboard = cb_save
  37.  
  38. "Escape any special characters in the selection
  39. let escaped_selection = EscapeString(selection)
  40.  
  41. return escaped_selection
  42. endfunction
  43.  
  44. " Start the find and replace command across the entire file
  45. vmap <leader>z <Esc>:%s/<c-r>=GetVisual()<cr>/
  46.  
  47. vnoremap <C-r> <Esc>:%s/<C-r>+//gc<left><left><left>
  48.  
  49. function! GetVisual() range
  50. let reg_save = getreg('"')
  51. let regtype_save = getregtype('"')
  52. let cb_save = &clipboard
  53. set clipboard&
  54. normal! ""gvy
  55. let selection = getreg('"')
  56. call setreg('"', reg_save, regtype_save)
  57. let &clipboard = cb_save
  58. return selection
  59. endfunction
  60.  
  61. vmap <leader>z :%s/<c-r>=GetVisual()<cr>/
  62.  
  63. :'<,'>
  64.  
  65. :'<,'>s/red/green/g
  66.  
  67. :%s,%V_.*%V/,**&**,c
  68.  
  69. :%s!%V_.*%V/!=system("base64 -w 0",@")!c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement