Main Content

Copy and paste / cut and paste and other vi techniques

Archive - Originally posted on "The Horse's Mouth" - 2007-11-20 01:11:39 - Graham Ellis

* If you want to duplicate a line, you can yank it with Y into the default yank buffer, then move your cursor and push it out with p or P to push it after or before the current line.

* To move a line, delete it with dd which puts it into the yank buffer, then push it with p or P.

* The number of lines to be yanked or deleted can by typed in before you Y or dd and vi will yank or delete that number of lines.

* If you want to remember whereabouts in your text you are so that you can come back later, you can drop a marker - ma will set a marker "a" and you can return to that marked line later using 'a - that's a quote followed by the marker name.

* The %command will jump the cursor to a matching bracket

* J joins 2 lines together

* and :e![cr] says "I made a right mess of that - abandon my changes and re-read the input file