简体   繁体   中英

How to add ^M to end of command in a macro on gvim for windows

Sample macro reg a :s/a/b/^M:s/c/d/^M The ^M's are valid.

I'm trying to save that to my _gvimrc file Which technically works but the ^M's are invalid.

let @a = ':s/a/b/^M:s/c/d/^M'

When I run it I get "Trailing Characters" error.

I've tried various things like \\r, \\n, and \\r\\n.

So the question is, is there some way to get a newline into my saved macro?

I should also add that if there is a better way to go about this that does not involve macros I'm open to suggestions. I have 3 or 4 find and replace commands that I want to run against my log files.

Use <cr> instead. And possibly <bar> the the one in between the two calls -- I never remember.

Otherwise, You could also have defined a command ( :h :command )

" <bar> or <cr> ? i.e: untested
:command! -nargs=0 -range=1 MySub :s/a/b/<bar>:s/c/d/

Both literal ^M as well as double-quoted, escaped \\<CR> should work just fine:

let @a = 's/a/b/^M:s/c/d/^M'
let @b = "s/a/b/\<CR>:s/c/d/\<CR>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM