Vim中显示不可见字符
:set invlist, 或 :%!
或还可以自己定义:
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:< set list
:set nolist
可以回到正常的模式
cat -A file 也可以显示不可见字符
dos2unix
is a commandline utility that will do this, or :%s/^M//g
will if you use Ctrl–v Ctrl–mto input the ^M, or you can :set ff=unix
and vim will do it for you.
Change the lineendings in the view:
1 2 3 4 5 |
:e ++ff=dos :e ++ff=mac :e ++ff=unix |
This can also be used as saving operation (:w alone will not save using the lineendings you see on screen):
1 2 3 4 5 |
:w ++ff=dos :w ++ff=mac :w ++ff=unix |
And you can use it from the command-line:
1 2 3 4 |
for file in $(ls *cpp) do vi +':w ++ff=unix' +':q' ${file} |
1 |
:set fileformat=unix |
For more information, see the vim help :
1 2 |
:help fileformat |
dos2unix
can directly modify the file contents.
You can directly use it on the file, with no need for temporary file redirection.
1 2 |
dos2unix input.txt input.txt |
The above uses the assumed US keyboard. Use the -
437 option to use the UK keyboard.
1 |
dos2unix -437 input.txt input.txt |
@ https://gist.github.com/sparkida/7773170
1 2 |
find $(pwd) -type f -name "*.ext" | while read file; do sed -e 's/^M//g' -i "$file"; done; |
also, as mentioned above ^M = Ctrl+V + Ctrl+M (don’t just type the caret “^” symbol and M)
1 2 3 |
%s/\r\+$//g |
that fill find all carriage return signs (one and more reps) up to the end of line and delete, so just
\n
will stay at eol.
1 |
0 Comments