I simply want to map < leader> pu to erase all occurrences of the carriage return character (represented as ^M) in a file.
I can execute the command:
:%s/\r//g
and it works.
Any attempts to use vim.keymap.set in my remap.lua file, however, error out when I try to source it.
Attempts include:
vim.keymap.set('n', '<leader>pu', vim.cmd('%s/\r//g'))
Errors with "Pattern not found:" using square brackets errors with "Pattern not found:\r"
vim.keymap.set('n', '<leader>pu', vim.cmd.substitute{ range = '%', args = {'\r',''} })
Errors with " Invalid command arg: expected non-whitespace"
An attempt with a different character, 'r', sources, but applies the command inside the sourced file instead of mapping it.
vim.keymap.set('n', '<leader>pu', vim.cmd('%s/r//g'))
I have other mappings using vim.cmd that work fine, and do not apply in the remap file.
Maybe this is a skill issue, but I need some assistance.
:help file-formats
. Would:set fileformat=unix
solve your problem? This will only affect CRLF line endings while your regexp will also erase CR characters not at the end of a line. Depends on what you want to achieve.