简体   繁体   中英

Quickest way to paste block of text into the vi editor from an external source

例如,从网页复制配置部分,然后将其粘贴到您在 vi 中打开的 .conf 文件中。

  1. Enter insert mode (Type i )
  2. Type: Ctrl + Shift + v

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.

The real answer:

  1. :set paste

  2. Enter Insert Mode: hit i

  3. Paste: Command + v or Control + v

  4. ESC

  5. :set nopaste

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.

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 .

最简单的方法是复制文本,然后在 Vim 中以INSERT模式右键单击要粘贴的位置。

If you are using gVim , hit Ctrl + R and then either * or + in insert mode. It will paste the last copied text.

The quickest way is to paste it using whatever paste key your system uses (eg ⌘-v for Macs, Ctrl-V for Windows, etc.) in insert mode.

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

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.

As others have said, if you're in insert mode, you can also use <Cr>* , but why? Your normal pasting flow is most likely better. Understanding the * register and <Cr> 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.

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.

Ctrl-V/ Apple-V? Just make sure you're in insert mode in vi (i)

插入模式下使用您的系统粘贴快捷键,或者如果您的源在另一个文件中,您可以键入:r <fileName> ,它将粘贴到光标的当前位置。

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.

The middle click could be a both left-right key if you're using a touchpad.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM