The fastest way to insert a block of text into a Vi editor from an external source

For example, copying the conf section from a web page, and then pasting it into the .conf file that you opened in Vi.

+7
linux vi text-editor
source share
10 answers

Or, if you use the system case, you can paste it without using it in insert mode:

"*p 

This inserts the system clipboard at the cursor point. No insert mode required.

+11
source share
  • Enter Insert Mode (Type i )
  • Type: ctrl - shift - v
+15
source share

One thing to keep in mind is sometimes Vim auto-indent text. This is mostly fine, but sometimes it will ruin the text you paste into the document.

If your indentation is wrong, delete the embedded text, type :set paste , paste the text again, and when you're done, type :set nopaste .

+11
source share

The real answer is:

  • :set paste

  • Enter input mode: press i

  • Paste: Command + v or Control + v

  • :set nopaste

+7
source share

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

+2
source share

If you are using gvim, press CTRL-R, then either * or + in insert mode. It pastes the last copied text.

+1
source share

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

0
source share

You use a hotkey to insert folders in Insert mode, or if your source is a different file, you can type: r and it will be inserted at the current location of your cursor.

0
source share

The easiest way on * nix is ​​to select it with the mouse and paste it into vim with a middle click after putting vi into Insert mode.

Middle click can be either left or right key if you use the touchpad

0
source share

The fastest way is to paste it using any key your system uses (for example, ⌘-v for macs, Ctrl-V for windows, etc.) in insert mode. Some terminals require the use of Shift-Ctrl-V . However, you can embed on the command line how you should embed in vim. However, this can cause some indentation issues, which includes :set paste . The quickest way to get in and out of this is to set the palette (see :help pastetoggle ). For example, I use

 set pastetoggle=<leader>p 

The reason for using the palette instead of matching is that if you set the display to insert mode, it will read it literally in insert mode. Thus, if you :set paste , go into insert mode and enter any imap , the mapping will not be completed, but instead, letter characters will be inserted. With pastetoggle you can get around this as it is a built-in function.

As others have said, if you are in insert mode, you can also use <Cr>* , but why? Your normal push-in flow is probably better. However, understanding the case * and <Cr> is an important skill. You can learn more about them in :help registers and :help i_CTRL-R . You can also use "*p , but if you type faster, your regular paste is impressive to me. Of course, you could compare this to something else, but then again ... why? You should get used to quickly enter the mode inserts using i, I, a, A, o, O, s, S, c, and C so you can be accurate.

0
source share

All Articles