Search code examples
vimvim-macros

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


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!


Solution

    • 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.