Vim Paste Code problem

Source: Internet
Author: User

Vim Paste Code problem

vim

When using Xshell for VIM operation, often directly paste some external code, and then paste on the following will appear progressive indentation of the situation, has not been to find out why, and line to get him back.

Transferred from: https://my.oschina.net/joshuazhan/blog/122539

    1. Background  
      When pasting the code in the terminal vim, it is found that the inserted code will have extra indentation and will accumulate on a line-by-row basis. The reason is that the terminal puts the pasted text into the keyboard cache (Keyboard buffer), which is handled by VIM as the user's keyboard input. When a newline character is encountered, if vim turns on auto indent, it defaults to inserting the previous line indent to the beginning of the next line, eventually causing the code to become messy.

    2. Resolve

      • Cancel Auto indent  ,
        in command mode, use ": Set Nosmartindent" and ": Set Noautoindent" To cancel Auto indent, then paste again. After the completion of the automatic indentation ": Set Smartindent" and ": Set Autoindent", the above commands can be used shorthand, such as ": Set Si", can be the help of vim ": Helps Smartindent" to see the corresponding instructions.
      • paste mode  
        Vim's edit mode, there is also a paste mode, in this mode, the text can be originally pasted into vim, to avoid some formatting errors. Enter and exit the mode with ": Set Paste" and ": Set Nopaste". A more convenient way is to set a shortcut to enter and exit paste mode in Vim, add a line to "~/.VIMRC" to configure "set pastetoggle=", so that the F12 can be quickly switched in paste mode, Of course, shortcut keys can be arbitrarily specified without conflict, specifically how to specify, refer to the accompanying tutorial links.
    3. reference

Http://vim.wikia.com/wiki/Paste_Indent_Problems
Tutorial (part_1) ">http://vim.wikia.com/wiki/mapping_keys_in_vim_-Tutorial(part_1)
Tutorial (part_2) ">http://vim.wikia.com/wiki/mapping_keys_in_vim_-Tutorial(part_2)
Tutorial (part_3) ">http://vim.wikia.com/wiki/mapping_keys_in_vim_-Tutorial(part_3)

Self-Summary:

      • After this situation, it is inevitable to see what the cause, there must be a solution or no solution
      • My own use of the paste mode, does not affect the use of other.

Vim Paste Code problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.