Monday, April 5, 2010

Vi editor copy and paste block example


"file.txt" is of the following format:


File "dummy.txt" contains the following lines:

$ cat dummy.txt
item2
item5
item9
item1

Required: In Vi, Copy the above lines from "dummy.txt" and paste to "file.txt" in the following format:






The solution:

In vim:

  • In "dummy.txt", press 'Ctrl v' to go to the "Visual Block" mode.
  • Select the required block from "dummy.txt" using the keyboard arrow keys and then press "y" for copy or "x" to cut the selected block to buffer.
  • In "file.txt" move cursor to the location you want the paste the copied block (in this example its Row 3 Column 23) and in command mode press P (capital P)
  • Done !
Related posts:

No comments:

© Jadu Saikia www.UNIXCL.com