I copied this file to vim and enumerated items got weird staircase pattern indent. Why so and how can I prevent this text corruption on a copy? It seems that it happens not only with enumerated items but rather in general every time I am copying some text it gets corrupted in Vim.

enter image description here


1 Answer 1


The reason why you get this "staircase" effect when pasting is that you have settings that will cause Vim to want to auto-indent this block, but the text you paste has indentation itself.

So every time a line break goes through the paste, Vim will copy the indentation from the line above, but then your paste will introduce another set of spaces/tabs from the indentation of the original document.

Another common artifact from pasting into a document is that Vim might want to rewrap long lines, especially when the 'textwidth' option is set.

The 'paste' option exists exactly for this use case, while 'paste' is enable, Vim masks the behavior of a handful of options, such as 'autoindent', 'textwidth' and 'formatoptions', among others, so that the interference with text coming from a paste is kept to a minimum. It also disables insert mode mappings and abbreviations.

Using 'paste' can be awkward, since you first enable it with :set paste, then start insert mode, actually paste the text, use <Esc> to leave insert mode and finally use :set nopaste to disable paste.

Plug-ins such as vim-unimpaired build on this option by creating commands ([op, ]op and yop) which will enable 'paste' for a single use and enter insert mode for you.

See vim-unimpaired's help for [op:

A toggle has not been provided for 'paste' because the typical use case of wrapping of a solitary insertion is inefficient: You toggle twice, but you only paste once (YOPO). Instead, press [op, ]op, or yop to invoke O, o, or 0C with 'paste' already set. Leaving insert mode sets 'nopaste' automatically.

(Note: the context is that for most other options handled by vim-unimpaired, the [o turns it on and the ]o turns it off...)

If you're running a Vim instance that has clipboard support, then you can also use one of the clipboard registers ("* or "+) to paste directly from the clipboard, using either "*p or "+p in Normal mode. Unfortunately, clipboard registers and ensuring they work in our system depends a lot of your system setup and it's a bit out of scope for this answer... But you should find a question that covers getting them to work in your setup (if you don't, then feel free to ask one.)

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.