Monday, March 31, 2008

Swapping Two Consecutive Lines in Vim

1. Go to edit mode by pressing Esc (Escape Button).

2. Go to the line which you want to swap with the line following.
Example:
1 Singh Jat
2 Mitesh

3. Press dd, then press p. You will find the two line are swapped.
Example:
1 Mitesh
2 Singh Jat

1 comment:

Unknown said...

There are 100 lines in my file, I want to swap every adjacent two lines, up to the end of file. How Can I do it.
Example:
1.MY
2.DESKTOP
3.SIZE
4.BIG

Now I want to make a file like,
1.DESKTOP
2.MY
3.BIG
4.SIZE

How can I do this?