On 2021-01-25, Chaoren Lin wrote:
> From time to time I'll need to search and replace something with a newline,
> and
> I'll do :s/<pattern>/\n/ and I'll get a bunch of ^@s. Then I'll remember: "oh,
> right, vim uses \r for newline in replacements". Instead of this happening
> every single time, I would like an option to change that behavior.
>
> As far as I can tell, there's no such option at the moment, and there doesn't
> seem to be a way to intercept the :s command and just change the replacement
> string.
>
> I don't want to change the default behavior. I'm sure you have your reasons
> for
> why it behaves this way in the first place. I just want something I can set in
> my .vimrc so I can permanently forget about this thing.
The thing is, if you did that, you'd break all the plugins that rely
on the current behavior. So that's out.
However, I think you could write your own command to do that. Name
it whatever you want, but of course it must begin with an upper-case
letter. If you want the :s command to invoke your command, you can
use the :cabbrev command to replace :s with your command, something
like this (adapted from my vimrc but otherwise untested):
cabbrev <expr> s ((getcmdtype() == ':' && getcmdpos() <= 2) ? 'MyS' : 's')
The details are left as an exercise for the reader, as I long ago
just got used to typing \r instead of \n in the replacement string.
Regards,
Gary
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20210125192946.GA5133%40phoenix.