1. Home
  2. Docs
  3. Manual
  4. Terminal connection
  5. VI/VIM copy and paste issue

VI/VIM copy and paste issue

When pasting content in Vim, formatting issues (such as messed-up indentation or unexpected comment symbols) usually occur due to automatic indentation, smart indentation, or improper mishandling of paste mode. Here’s how to fix it:

Method 1: Use “Paste Mode” before pasting

Vim’s paste mode temporarily disables auto-indentation, syntax-based indentation, and other features, ensuring pasted content retains its original formatting.

  1. In Vim’s normal mode, run:vim:set paste You’ll see -- INSERT (paste) -- at the bottom, indicating paste mode is active.
  2. Press i to enter insert mode, then paste your content (e.g., use Ctrl+V or right-click to paste from the system clipboard).
  3. After pasting, turn off paste mode:vim:set nopaste

Method 2: Temporarily disable indentation

If you prefer not to use paste mode, disable indentation features temporarily:

  1. In normal mode, run:vim:set noautoindent nosmartindent
  2. Press i to enter insert mode and paste your content.
  3. To restore indentation later (optional, for subsequent editing):vim:set autoindent smartindent

Method 3: Paste using Vim registers (avoid clipboard interference)

For content copied within Vim, use Vim registers to preserve formatting:

  • Copy with "+y (copy to system clipboard) or "*y (copy to primary clipboard).
  • Paste with "+p (paste from system clipboard) or "*p (paste from primary clipboard).

Summary: Method 1 (paste mode) is the most recommended—it’s simple and reliably prevents formatting issues. Just remember to enable paste before pasting and disable it with nopaste afterward.