5

This wikia page explains how to paste text from a different application into vim when in insert mode. Simply apply the command set paste and things will work as expected. After you are done, just enter command set nopaste to go back to the original state.

Is there some unwanted behavior of staying in the set paste state? If I put that command in my .vimrc, will it affect any other command?

1
  • See :h paste. Basically a lot of stuff gets disabled, so no, you don't want that.
    – VanLaser
    Commented Dec 13, 2015 at 22:49

3 Answers 3

3

As the documentation states setting the paste option disables many features:

 When the 'paste' option is switched on (also when it was already on):
                - mapping in Insert mode and Command-line mode is disabled
                - abbreviations are disabled
                - 'autoindent' is reset
                - 'expandtab' is reset
                - 'formatoptions' is used like it is empty
                - 'revins' is reset
                - 'ruler' is reset
                - 'showmatch' is reset
                - 'smartindent' is reset
                - 'smarttab' is reset
                - 'softtabstop' is set to 0
                - 'textwidth' is set to 0
                - 'wrapmargin' is set to 0
        These options keep their value, but their effect is disabled:
                - 'cindent'
                - 'indentexpr'
                - 'lisp'

You can of course stay in paste mode, but one usually doesn't, because it disables too many features.

1
  • thanks, I should check the documentation first next time.
    – solalito
    Commented Nov 22, 2015 at 13:08
2

The many undesirable side effects of 'paste' are explained in :help 'paste':

When the 'paste' option is switched on (also when it was already on):
    - mapping in Insert mode and Command-line mode is disabled
    - abbreviations are disabled
    - 'textwidth' is set to 0
    - 'wrapmargin' is set to 0
    - 'autoindent' is reset
    - 'smartindent' is reset
    - 'softtabstop' is set to 0
    - 'revins' is reset
    - 'ruler' is reset
    - 'showmatch' is reset
    - 'formatoptions' is used like it is empty
These options keep their value, but their effect is disabled:
    - 'lisp'
    - 'indentexpr'
    - 'cindent'

In short, :set paste is an abomination that should be used only when you can't avoid it and, even then, disabled as soon as possible.

Use Vim's built-in clipboard support as much as you can.

2
  • Sorry, Christian Brabandt just beat you to it :/
    – solalito
    Commented Nov 22, 2015 at 13:10
  • 1
    No competition, no problem.
    – romainl
    Commented Nov 22, 2015 at 13:15
1

The paste option is useful so that vim doesn't indent every pasted line by inserting a tab character (or spaces) in front of them which messes the formatting.

I've noticed two side effects that are a little annoying and are the reason why I don't put set paste inside my ~/.vimrc.

First, it disables auto-indentation when you're in insert mode even if you type your text normally (no pasting) because vim seems to not make the difference between pasted text and typed text.

Second, at one time I had mapped the jk sequence as escape (I don't have it anymore), and the mapping doesn't work when paste is set.

When I want to copy some text from another program inside vim in a terminal, in insert mode, I usually have the choice between <C-S-v>, <C-r>* or <C-r>+.

There's a vim plugin called vim-bracketed-paste that allows a recent terminal to tell vim that the text is being pasted from an external program. It solves the problem of extra indentation when pasting with <C-S-v> but not with <C-r>* or <C-r>+.

Note you can also paste while in normal mode with "+p or "*p. The first one allows you to paste what's inside the system clipboard, the second one what's selected in an external program.

Your Answer

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

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