Xen_mar
Xen_mar

Reputation: 9742

Recover a deleted file in VIM after running dG

I was smart enough to run the dG command in vim and instead of simply quitting my muscle memory put in a :wq.

Is there any way to restore the file?

Upvotes: 0

Views: 245

Answers (1)

romainl
romainl

Reputation: 196826

d<motion> cuts the text covered by <motion> into the unnamed register, ". Assuming you have a relatively "normal" setup, Vim should have written the content of that register to ~/.viminfo when you did :wq. If so, you should be able to edit the same file and put the content of that register back into the buffer.

  1. Edit your file in a new Vim session:

    $ vim filename
    

    The buffer should be empty.

  2. Inspect the content of every register with :registers to see if it is still stored. If you didn't use Vim in the mean time, register " should have it.

  3. If it is there, do the following, starting from normal mode:

     v                       " start visual mode
     "<name of register>p    " put from register <name of register>
    

Upvotes: 2

Related Questions