Linux 从外部源将文本块粘贴到 vi 编辑器的最快方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4402198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Quickest way to paste block of text into the vi editor from an external source
提问by asfsadf
For instance, copying a configuration section from a web page and then pasting it into a .conf file that you have open in vi.
例如,从网页复制配置部分,然后将其粘贴到您在 vi 中打开的 .conf 文件中。
采纳答案by Jordan Parmer
Or if you use the system register, you can paste without being in insert mode:
或者,如果您使用系统寄存器,则可以在不处于插入模式的情况下进行粘贴:
"*p
This will paste the system's clipboard at the point of the cursor. No insert mode needed.
这会将系统的剪贴板粘贴到光标处。不需要插入模式。
回答by Tyler Eaves
Ctrl-V/ Apple-V? Just make sure you're in insert mode in vi (i)
Ctrl-V/苹果-V?只要确保你在 vi (i) 中处于插入模式
回答by Ronnie Howell
Use your systems paste shortcut key while in Insertmode, or if your source is in another file, you can type :r <fileName>, and it will be pasted at the current location of your cursor.
在插入模式下使用您的系统粘贴快捷键,或者如果您的源在另一个文件中,您可以键入:r <fileName>,它将粘贴到光标的当前位置。
回答by Benoit
回答by matt
One thing to bear in mind: Sometimes Vim auto-indents text. This is mostly fine, but sometimes it messes up text that you paste into a document.
要记住的一件事:有时 Vim 会自动缩进文本。这基本上没问题,但有时会弄乱您粘贴到文档中的文本。
If your indentations are awry, remove the pasted text, type :set paste
, paste the text in again, and when you're done, type :set nopaste
.
如果缩进有误,请删除粘贴的文本,键入:set paste
,再次粘贴文本,完成后,键入:set nopaste
。
回答by Metiu
The easiest way on *nix is by selecting it with the mouse and pasting it in Vim with a middle click, after having put vi in insert mode.
在 *nix 上最简单的方法是在将 vi 置于插入模式后,用鼠标选择它并单击中键将其粘贴到 Vim 中。
The middle click could be a both left-right key if you're using a touchpad.
如果您使用的是触摸板,中键可能是左右键。
回答by Conner
The quickest way is to paste it using whatever paste key your system uses (e.g. ?-vfor Macs, Ctrl-Vfor Windows, etc.) in insert mode.
最快的方法是在插入模式下使用系统使用的任何粘贴键(例如?-vMac、Ctrl-VWindows 等)粘贴它。
Some terminals require you to use Shift-Ctrl-V. However you are able to paste onto the command-line is how you should paste into Vim. However, this can cause some problems with indentation, which is where :set paste
comes in. The fastest way to get in and out of this is to set a pastetoggle (see :help pastetoggle
). For example, I use
某些终端要求您使用Shift-Ctrl-V. 但是,您可以粘贴到命令行上,这就是粘贴到 Vim 中的方式。但是,这可能会导致一些缩进问题,这就是缩进的问题:set paste
。进入和退出这种状态的最快方法是设置一个 pastetoggle(请参阅 参考资料:help pastetoggle
)。例如,我使用
set pastetoggle=<leader>p
The reason to use a pastetoggle instead of a mapping is because if you set a mapping insert mode, it will read it literally when in paste mode. Thus if you :set paste
, go into insert mode, and type in any imap
the mapping will not be completed, but instead the literal characters will be inserted. With pastetoggle
you can get around that since it's a built-in feature.
使用 pastetoggle 而不是映射的原因是因为如果您设置映射插入模式,它会在粘贴模式下按字面意思读取它。因此,如果您:set paste
进入插入模式,并输入任何imap
映射将不会完成,而是会插入文字字符。有了pastetoggle
你可以得到周围,因为它是一个内置功能。
As others have said, if you're in insert mode, you can also use <C-r>*
, but why? Your normal pasting flow is most likely better. Understanding the *
register and <C-r>
is an important skill however. You can read more about them at :help registers
and :help i_CTRL-R
. You could also use "*p
, but if you're faster at typing that than your normal paste I'm impressed.
正如其他人所说,如果您处于插入模式,您也可以使用<C-r>*
,但为什么呢?您的正常粘贴流程很可能会更好。然而,理解*
寄存器<C-r>
是一项重要的技能。您可以在:help registers
和阅读更多关于它们的信息:help i_CTRL-R
。您也可以使用"*p
,但如果您的输入速度比普通粘贴更快,我会印象深刻。
Of course you could map that to something else, but again... why? You should get used to quickly getting into insert mode with i, I, a, A, o, O, s, S, c, and C
so that you can be precise.
当然你可以把它映射到别的东西上,但同样......为什么?您应该习惯于快速进入插入模式,i, I, a, A, o, O, s, S, c, and C
以便您可以精确。
回答by RationalPi
- Enter insert mode (Type i)
- Type: Ctrl+ Shift+ v
- 进入插入模式(类型i)
- 类型:Ctrl+ Shift+v
回答by Arian Faurtosh
The real answer:
真正的答案:
:set paste
Enter Insert Mode: hit i
Paste: Command+ vor Control+ v
ESC
:set nopaste
:set paste
进入插入模式:点击 i
粘贴:Command+v或Control+v
ESC
:set nopaste
回答by Barth
The easiest way is just to copy the text and just right click where you want to paste it in Vim in INSERTmode.
最简单的方法是复制文本,然后在 Vim 中以INSERT模式右键单击要粘贴它的位置。