Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
- " search for visually hightlighted text
- vnoremap <c-f> y<ESC>/<c-r>"<CR>
- %s//<your-replacement-string>
- " Escape special characters in a string for exact matching.
- " This is useful to copying strings from the file to the search tool
- " Based on this - http://peterodding.com/code/vim/profile/autoload/xolox/escape.vim
- function! EscapeString (string)
- let string=a:string
- " Escape regex characters
- let string = escape(string, '^$.*/~[]')
- " Escape the line endings
- let string = substitute(string, 'n', '\n', 'g')
- return string
- endfunction
- " Get the current visual block for search and replaces
- " This function passed the visual block through a string escape function
- " Based on this - https://stackoverflow.com/questions/676600/vim-replace-selected-text/677918#677918
- function! GetVisual() range
- " Save the current register and clipboard
- let reg_save = getreg('"')
- let regtype_save = getregtype('"')
- let cb_save = &clipboard
- set clipboard&
- " Put the current visual selection in the " register
- normal! ""gvy
- let selection = getreg('"')
- " Put the saved registers and clipboards back
- call setreg('"', reg_save, regtype_save)
- let &clipboard = cb_save
- "Escape any special characters in the selection
- let escaped_selection = EscapeString(selection)
- return escaped_selection
- endfunction
- " Start the find and replace command across the entire file
- vmap <leader>z <Esc>:%s/<c-r>=GetVisual()<cr>/
- vnoremap <C-r> <Esc>:%s/<C-r>+//gc<left><left><left>
- function! GetVisual() range
- let reg_save = getreg('"')
- let regtype_save = getregtype('"')
- let cb_save = &clipboard
- set clipboard&
- normal! ""gvy
- let selection = getreg('"')
- call setreg('"', reg_save, regtype_save)
- let &clipboard = cb_save
- return selection
- endfunction
- vmap <leader>z :%s/<c-r>=GetVisual()<cr>/
- :'<,'>
- :'<,'>s/red/green/g
- :%s,%V_.*%V/,**&**,c
- :%s!%V_.*%V/!=system("base64 -w 0",@")!c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement