#print Yanking and Putting Often you will want to move text from one place in the file to another. You do this in vi by first deleting it, all in one chunk (e.g. to delete 5 lines type '5dd', not 'dddddddddd'), moving to the new location, and typing 'p'. This stands for 'put' and it simply inserts the most-recently deleted text. The 'p' command will insert it after the current line or character (depending upon the type of delete done) and 'P' inserts it before said line/character. If you just want to copy the text, what you'd like is some way to 'delete' the text without really deleting it. For this, vi provides the 'yank' command, which does just that. To copy five lines to somewhere else, say '5yy' (this memorizes the next five lines), then move the cursor to the new location and hit 'p'. The 'y' command can use any targets that 'd' can use. (In general, targetable commands can always be doubled, as in 'yy', to make them refer to the current line.) Type 'ready' now to try out yanking and putting. #user #create YankPut 'p' puts the most-recently deleted text after the current position and 'P' puts it before the current position. 'y' works just like the 'd' command except that it doesn't actually delete the text, it only memorizes it. Note that putting doesn't make vi forget what it last yanked or deleted. That is, you can yank something once and then put it several times, to make several copies of it. --------------------------------------------------------------------------- # cat /usr/share/learn/vi/longtext >> YankPut vi YankPut #next 5.3 10