I often use a command or script to delete text and after I do an undelete (u) I want to see what has been previously deleted by the command/script.
Is it possible to highlight the previous deleted text when use the undelete command? (or even better match the previous deleted text in a find "/" command)
If you just deleted some text using d, you can use /<CTRL-R>" to match the text you just deleted (even if you just undid the delete with u).
This won't work if the deleted text contains newlines or regex meta-characters (like \ or [). If that's likely, try:
/\V<CTRL-R>=substitute(substitute(getreg('"'), "[\\/]", '\\\0', 'g'), "\n", '\\n', "g")
\V - very nomagic - turns off most regex meta-characters<CTRL-R>= - insert the evaluation of a vim expressionsubstitute(..., "\n", '\\n', "g") - escape all the newlines in the given stringsubstitute(..., "[\\/]", '\\\0', 'g') - escape all slashes and backslashes in the given stringgetreg('"') - get the contents of the " register, which contains the most recently yanked and/or deleted textThis is a bit wordy, so if you find yourself needing to do it often, you can bind it to a command in your ~/.vimrc:
" use ,/ in normal mode to match the most recently deleted or yanked text
nmap ,/ /\V<C-R>=substitute(substitute(getreg('"'), "[\\/]", '\\\0', 'g'), "\n", '\\n', "g")<CR><CR><CR>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With