开发者

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

开发者 https://www.devze.com 2023-01-30 07:19 出处:网络
For instance, copying a configuration section from a web page and then pasting it into a .co开发者_开发问答nf file that you have open in vi.

For instance, copying a configuration section from a web page and then pasting it into a .co开发者_开发问答nf file that you have open in vi.


  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.


The easiest way is just to copy the text and just right click where you want to paste it in Vim in INSERT mode.


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


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


Use your systems paste shortcut key while in Insert mode, 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.


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 quickest way is to paste it using whatever paste key your system uses (e.g. ⌘-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 <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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号