2

I want to be able to open a file using vim but immediately have it execute this command %s/^M/\r/g

I am trying to do this with the:

nvim path/to/file -c "%s/^M/\r/g"

nvim says that the pattern ^M is not found but they are in the file. How can I pass the correct character in the command line?

I realise that c-vM works if you are in vim but I am trying to replicate the c-vM character in the terminal.

pdoak
  • 721
  • 8
  • 21
  • 1
    Ciro Santilli 刘晓波死 六's answer to this question should be sufficient for what your are trying to do, https://stackoverflow.com/questions/5939142/replacing-carriage-return-m-with-enter. – Patrick Bacon Aug 20 '17 at 03:16
  • I will just run `dos2unix file.txt` – dlmeetei Aug 20 '17 at 08:38
  • Possible duplicate of [Replacing carriage return ^M with Enter](https://stackoverflow.com/questions/5939142/replacing-carriage-return-m-with-enter) – dlmeetei Aug 20 '17 at 08:44
  • In order to insert ^M you must press Ctrl-v probably you are inserting two characters instead one. You should also make nvim suppress possible error messages appending `e` at the command `nvim path/to/file -c "%s/^M/\r/ge"` – SergioAraujo Aug 20 '17 at 17:23

1 Answers1

2
nvim path/to/file -c "set fileformat=unix"

As quoted here https://stackoverflow.com/a/26903948/2544873

Tinmarino
  • 3,693
  • 24
  • 33