home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Learning the vi Editor

Learning the vi EditorSearch this book
Previous: D.4 Problems with vi Commands Appendix D
Problem Checklist

D.5 Problems with Deletions

  • You've deleted the wrong text and you want to get it back.

    There are several ways to recover deleted text. If you've just deleted something and you realize you want it back, simply type u to undo the last command (for example, a dd ). This works only if you haven't given any further commands, since u only undoes the most recent command.

    You can still recover a recent deletion, however, by using the p command, since vi saves the last nine deletions in nine numbered deletion buffers. If you know, for example, that the third deletion back is the one you want to restore, type:


    to "put" the contents of buffer number 3 on the line below the cursor.

    This works only for a deleted line . Words, or a portion of a line, are not saved in a buffer. If you want to restore a deleted word or line fragment, and u won't work, use the p command by itself. This restores whatever you've last deleted.

Previous: D.4 Problems with vi Commands Learning the vi Editor  
D.4 Problems with vi Commands Book Index  

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System