Pasting code not auto indenting code in yaml even with 'set ai' and 'set paste'

Viewed 92

I'm experiencing troubles with vim and the autoindent mode. I have set up autoident, paste, smartindent and a lot of more options I have seen on stackoverflow's answers, but don't get the solution.

My problem is that when pasting code, the first line of the code is not leading the rest of the block indentation. Will explain it with two pictures:

  1. This is my code. I will paste on line 53:

    enter image description here

  2. When I paste the code, only the first line is indented in the place I had the cursor (line 53):

    enter image description here

  3. And this is the result I was expecting:

    enter image description here

How could I get the same indentation as in image 3? Thank you in advance!

1 Answers

I found the solution. I was using a version of vim which had disabled the clipboard. To check it:

vim --version | grep clipboard

Out of this command you should see "+clipboard" and "+xterm_clipboard"

If not, try to install vim-gtk3 or vim-x11

Once you have check that you can work with the clipboard, use this command to paste:

"+]p

  • "+ will use the clipboard register
  • ] this tells vim to correct the indentation
  • p paste
Related