edit a Vim macro with a range operation that refers to a tag

61 Views Asked by At

I created a macro with a range (http://vim.wikia.com/wiki/Ranges) operation like:

:.,'bs/ .*$\n/ /ge^M

I then wanted to edit it, which I would normally do using let (http://vim.wikia.com/wiki/Macros#Editing_a_macro):

:let @b=':.,'bs/ .*$\n/ /ge^Mdd'

But for these examples, the ' in the macro definition causes the edit to fail. How to resolve this? Either an alternate range syntax or a way to escape the quote when defining.

I know I can re-record the macro, but the actual version is much longer than this!

1

There are 1 best solutions below

0
Ingo Karkat On BEST ANSWER
  • Single quotes need to be doubled inside such string: :let @b=':.,''bs/ .*$\n/ /ge^Mdd'
  • You could use double quotes, but then also double backslashes (if there are any) :let @b=":.,'bs/ .*$\\n/ /ge^Mdd"
  • Instead of :let, you could :put b into a scratch buffer, edit, then "by$ into the register again.