I used to know a vim command sequence where I would remove all the non-printable extraneous characters in a file, like ^M
on Windows files that ended up with col -xb
, but I can't recall the keyboard sequence before I enter the col -xb
command to say "do this from top-to-bottom of file." Does this ring a bell to anybody?
Asked
Active
Viewed 142 times
2

Chris F
- 14,337
- 30
- 94
- 192
-
1Do you mean to ask what is the syntax for calling an external command from within Vim and passing it the contents of the buffer? Then the answer is `:%!col -xb` (`:` for entering the ex-command mode as usual, `%` for selecting all lines (you can also write other ranges, like `100,150` for the lines 100 to 150) and `!` for piping it through an external command. – Maëlan Sep 08 '21 at 20:07
-
That's it. Put this as an answer and I'll accept it. Thanks – Chris F Sep 08 '21 at 20:22
2 Answers
3
:%!col -xb
:
enters the ex-command mode as usual,%
selects all lines (you can also write other ranges, like 100,150
for lines 100 to 150) and !
pipes them through an external command.

Maëlan
- 3,586
- 1
- 15
- 35
1
run the following command in vim:
:set fileformat=unix
it worked for me, and also check out: Are shell scripts sensitive to encoding and line endings?

serax
- 218
- 2
- 11
-
None of those worked form me, I tried most of them before posting. This is not an answer to the specific question though, but thanks. – Chris F Sep 08 '21 at 20:02
-
If your problem is that Vim displays `^M` at the end of every line, that is because your file follows DOS/Windows’ convention (i.e. “CR LF”) for line endings and Vim wrongly interprets it as the Unix/Linux convention (i.e. “LF”), which leaves one uninterpreted CR character before every line ending. To just make them disappear from display, have Vim re-interpret the file correctly with `:e ++ff=dos`. If *after that*, you also want to actually remove them from the file, then run `:set ff=unix` (as advised by this answer) and save your buffer. This recodes the file. – Maëlan Sep 08 '21 at 20:15
-
See [this question](https://stackoverflow.com/questions/5843495/what-does-m-character-mean-in-vim) for many more ways of dealing with / getting rid of CR LF in Vim. – Maëlan Sep 08 '21 at 20:19