0

I am using Putty on Windows to connect to a Linux server.

On the Linux server I am using Vim to edit code files.

I am using my mouse to select an area to copy and then right click to paste the copied code.

So far I am aware of 2 settings that alter this copy/paste behavior:

  • :set paste
  • :set autoindent

Sample YAML file:

a1: value1
a2: value2
a3:
  a4: value4
a5:
  a6: value6
  a7:
    - value7

b1: value1
b2: value2
b3:
  b4: value4
b5:
  b6: value6
  b7:
    - value7

What I want to do:

Copy the whole "a" code sample under b3: in the "b" code sample while keeping the original indentation.

b1: value1
b2: value2
b3:
  b4: value4
  a1: value1
  a2: value2
  a3:
    a4: value4
  a5:
    a6: value6
    a7:
      - value7
b5:
  b6: value6
  b7:
    - value7

Outcome:

All combinations (paste, autoindent), (paste, noautoindent), (nopaste, autoindent), (nopaste, noautoindent) are incapable of performing pastes correctly. They all mess up the indentation in 1 way or another.

Is there any solution to this issue without using yank/p to copy/paste. Using a mouse is so much better in my opinion when you are not on a serial console.

14
  • 1
    :h ]p, :h ]P?
    – r_31415
    Jul 30, 2022 at 16:42
  • @r_31415 Can you provide an example on how to use it ?
    – Subzero123
    Jul 30, 2022 at 17:47
  • Did you read the help files? Did you press ]p in the desired region after copying your text?
    – r_31415
    Jul 30, 2022 at 18:10
  • p, ]p, ]P, "*]p, "+]p either output nothing (when I select with my mouse) or the last line from the multiple lines that I copied (from a different place with CTRL+C).
    – Subzero123
    Jul 30, 2022 at 23:02
  • Since you're providing a self-contained example: i.imgur.com/PQtLjNm.gif but that's not going to work if you're pasting from your clipboard.
    – r_31415
    Jul 31, 2022 at 0:34

3 Answers 3

0

If you want to paste with Ctrl+Shift+V and keep the formatting, run the command on vim

:set paste

After copying continue as normal by typing:

:set nopaste

1
  • PuTTY pastes with Shift + Insert from what I see. I tested it and it pastes the copied text at the beginning of the line instead of where my cursor is.
    – Subzero123
    Aug 1, 2022 at 23:08
0

you may also need notabs. If your original has tabs, copy paste may translate them to spaces. Avoiding tabs avoids the problem.

1
  • There are no tabs, only spaces. I use: set expandtab set tabstop=2 set softtabstop=2 set shiftwidth=2
    – Subzero123
    Aug 1, 2022 at 22:58
0

normal mode: "+p OR "*p

OR

:set paste, S-insert, :set nopaste

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.