vi:粘贴到文件顶部

发布于 2024-08-03 11:11:31 字数 439 浏览 3 评论 0原文

vi 困扰我的一件事是,paste (p) 在我所在的行之后插入行,这使得我无法在文件顶部插入内容。

例如,假设我正在检查并将 UTF-8 声明添加到几个文件的顶部:

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

yy 并且它被拉出。好的。

我切换到另一个文件, gg 到达顶部, p 粘贴,我最终得到这样的结果:

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

这不是我想要的。

现在,我总是在寻找可以用 vi 做的新事情,所以我认为这是我应该能够做的事情,但只是不知道该怎么做。然而,搜索并不能提供非常有用的结果,因为每个人和他们的母亲都有一个 vi(m) 备忘单,其中包含 p 和 gg。因此,我想到了这样的问题:这可能吗?如果可能的话,如何实现?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囚我心虐我身 2024-08-10 11:11:31

P(大写)插入上方/之前,p(小写)插入下方/之后。

oO 类似。 o 在当前行之后插入一行,O 在当前行之前插入一行。我经常使用这些命令。

您可以使用 [[1Ggg:1 到达文件的开头>。

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 [[, 1G, gg, or :1<CR>.

昵称有卵用 2024-08-10 11:11:31

另一个选项:

:1put! 将文本放在第一行之前,而不必将光标移到那里。

:1put 将文本放在第一行之后。

https://vimhelp.org/change.txt.html#%3Aput

Another option:

:1put! to put the text before the first line without having to move the cursor there.

:1put to put the text after the first line.

https://vimhelp.org/change.txt.html#%3Aput

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文