Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vi pasting messes with formatting

Tags:

vim

vi

When I opened a vim editor on terminal, I copied the following text to clipboard from another source

    int thisVal = findMin(m);
    // System.out.println(val);
    m.add(val);

But it becomes

                int thisVal = findMin(m);
                // System.out.println(val);
                //                      m.add(val);

Why is this case and how to paste correctly with the formatting? Thank you.

like image 922
Qiang Li Avatar asked Jan 28 '13 00:01

Qiang Li


People also ask

How do I paste format in vi?

To put the yanked or deleted text, move the cursor to the desired location and press p to put (paste) the text after the cursor or P to put (paste) before the cursor.

Can you copy paste in vi?

In Vi/Vim, the paste operation is called a put operation. The only way to paste in Vi/Vim is to place the cursor at the desired location and use “P” to paste text before or after the cursor.

How do I turn off auto indent in Vim?

vim Inserting text Disable auto-indent to paste code Just press F3 in insert mode, and paste. Press F3 again to exit from the paste mode.


1 Answers

:set paste

should cause indenting to work correctly. As uku points out, you can read more information on paste mode using

:h paste

you can turn off paste mode with

:set nopaste
like image 163
Paul Sanwald Avatar answered Oct 14 '22 11:10

Paul Sanwald