VI中替换换行符

sh/bash/dash/ksh/zsh等Shell脚本
回复
yuffey
帖子: 193
注册时间: 2007-09-06 16:24
来自: 中国上海

VI中替换换行符

#1

帖子 yuffey » 2007-11-29 10:24

Windows files has line feed and carriage return. When such files are copied to *nix like OS, vim / vi shows ^M characters at the end of each line.

To get rid of those ^M use:

代码: 全选

1,$ s/^M//gc
or
% s/^M//gc

To type ^M hit ctrl+v first and then M.
Anonymous, January 31, 2007 14:11

代码: 全选

For ^M hit CTL-v then CTL-M or CTL-v enter
Anonymous, January 31, 2007 14:24
one of the oldest topics ever, see vimtip #26

Anonymous, January 31, 2007 23:28
Note that, for people using Vim with Windows keybindings, CTRL-V is (naturally) the paste operation;
so, to produce a

代码: 全选

 ^M, you have to type CTRL-Q then CTRL-M 
回复