In VIM, we generate a test file under shell: $ echo-e & quot; I \ rlove \ rWQ. & quot; & gt; test, and then open it with vim. it is really I ^ Mlove ^ MWQ. run: % s/\ r/g to find that the file is normal. But there is an exception here: % s/\ r/g... in VIM, we generate a test file in shell: $ echo-e "I \ rlove \ rWQ. "> test and use vim to open it. it is really I ^ Mlove ^ MWQ. run: % s/\ r/g to find that the file is normal. However, there is an exception here. the command % s/\ r/g replaces \ r with \ r, and nothing should change, how can I replace the line break of a file? After a careful check, we found that this problem should start with different line breaks in different systems. The following table is quite familiar to everyone: windows/dos unix mac line break crlf lf cr in SHELL represents \ r \ n \ r16 hexadecimal character 0d0a 0a 0d: in the % s/\ r/g command, the meaning of the First \ r and the second \ r may be different. The First \ r represents the 0d, that is, CR. The second \ r is determined by VIM based on the built-in fileformat variables. See the following table: \ n \ r: set ff = dos 00 0d0a (\ n \ r): set ff = unix 00 0a (\ n): set ff = mac 00 0d (\ r) OK, now we can explain why the above: % s/\ r/g has changed 0d to 0a. There are two other tips: depending on fileformat, vim will automatically add a line break at the beginning of the file, unless it is vim-B xxx at startup, and set noeol must be enabled at the same time. In any case, \ n in VIM is 00 and is displayed as @ in VIM @
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.