The solution to the problem of copy-paste indentation disorder in Vim

foreword

This is a note-taking note to keep little tricks from being forgotten.

I don't know if you will have this kind of trouble. For example, there is a beautifully indented code implementation in Android Studio, such as:

public void sayHello() {
    String msg = "Hello Vim Paste Mode";
    System.out.println(msg);
}
  • 1
  • 2
  • 3
  • 4

When you put this beautifully indented code directly ctrl+c, ctrl+v to Vim, the following disgusting situation will appear: 
disgusting_code

It can be seen that this way of direct pasting will lead to code loss and indentation disorder.


solution

vim enters paste mode, the command is as follows:

:set paste
  • 1

After entering paste mode, press i again to enter insert mode, copying and pasting is normal. 
beautiful_code

In command mode, enter

:set nopaste
  • 1

Cancel paste mode.

The paste mode mainly helps us do the following things:

  • textwidth is set to 0
  • wrapmargin is set to 0
  • set noai
  • set nosi
  • softtabstop is set to 0
  • revins reset
  • ruler reset
  • showmatch reset
  • formatoptions use empty value

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325969214&siteId=291194637