tags:

views:

158

answers:

1

One thing that's bothered me with vi is that paste (p) inserts lines after the line I'm on, which makes it impossible for me to insert things at the top of a file.

For instance, say I'm going through and adding a UTF-8 declaration to the top of a few files:

# -*- coding: utf-8 -*-

yy and it's yanked. Good.

I switch over to another file, gg to get to the top, and p to paste, and I end up with something like this:

import sys
# -*- coding: utf-8 -*-

which is not what I want.

Now, I'm always finding new things I can do with vi, so I was figuring that this was something I should be able to do, but just didn't know how to. Searching, however, doesn't provide very useful results, as everybody and their mother has a vi(m) cheatsheet, with both the p and gg in it. Thus, I come to SO: is this possible, and if so, how?

+15  A: 

P (capital) inserts above/before, as p (lower-case) inserts below/after.

o and O are similar. o inserts a line after the current one, and O inserts before. I use those commands frequently.

You can get to the beginning of the file using [[ or 1G.

strager
Very much correct. I remember the days of not knowing that -- a long time ago.
gahooa
Ah hah! I knew about o and O, but I didn't make the connection to p.
Xiong Chiamiov
@gahooa, I remember the dark ages where I didn't know about 'a' and always used 'i' and had to delete characters at the end of lines every time I wanted to append something. xD
strager
I remember using cl instead of s. And the examples could never stop.
ddvlad