1

When I am inserting a big block of code or text, often I will want to copy and paste text from elsewhere into that block.

Is the only way to do this to leave insert mode, go get the text and paste, then go back to insert mode?

2
  • 1
    copy and paste text from elsewhere Do you mean elsewhere in vim, e.g. in the same file, or elsewhere as in from your browser?
    – DJMcMayhem
    May 24, 2016 at 21:20
  • 1
    Elsewhere in the same buffer. For example, often I will have certain long variable names or constant names that are used repeatedly. In a notepad-like editor, I double click on the variable and ctrl-C ctrl-V to paste it. I am kind of looking to translate this workflow to vim. May 24, 2016 at 21:24

3 Answers 3

7

You don't have to leave insert mode if you don't want to. While in insert mode, paste text from a register by pressing <C-r>registername, e.g. <C-r>+ to paste from system clipboard or <C-r>" to paste lines yanked inside vim (from the unnamed register).

Edit:

After the clarification in your comment, I would recommend that you adapt a different workflow in vim:

While being in insert mode, just type the beginning of your long constant or variable name, e.g. the first 3 characters followed by <C-p>. Vim will use its built-in autocompletion to complete the word. If more than one word starts with the same sequence, press <C-p> repeatedly (or use <C-n> to select previous item).

2

I'm not exactly sure what you want to do here, but I think you're looking for :h i_ctrl-r.

If you're in insert mode, and need to copy text from a webbrowser or other application (or window). Do the copy, return to vim, and type <C-R>* or <C-R>+.

If you need to insert something yanked earlier in vim while staying in insert mode, you might be looking for <C-R>" instead

0

If you want to use vim like a traditional, notepad-like editor, you can use select mode. This is like visual mode, but with your mouse, and it behaves more like a traditional editor does. Add these to your .vimrc

set selectmode+=mouse
snoremap <C-v> "+y
snoremap <C-x> "+d

Then for paste, do this:

inoreamp <C-v> <C-o>"*p

Personally, I recommend against mapping to <C-v> since this is really useful in insert mode. I would map it to <M-v> (alt+v) but it's up to you.

2
  • I don't want to use it with the mouse. I want to use vim like vim. I just need to know what the workflow is for cobbling together a text that has lots of redundant words in it. May 24, 2016 at 21:36
  • 1
    Oh, in that case definitely disregard my advice. :P In that case, I would just use <C-p> like cbaumhardt recommended.
    – DJMcMayhem
    May 24, 2016 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.