1

How can I make a mapping that includes a for-loop?

xnoremap <leader>y :for i in [1, 2, 3, 4] | echo i | endfor

errors E121: Undefined variable: i

and

xnoremap <leader>y :for line in getlines(1, 2) | echo line | endfor

errors E588: :endfor without :for

1 Answer 1

1

:help :bar is help for the | pipe line separator

You need to escape them to use them in arguments:

xnoremap <leader>y :for i in [1, 2, 3, 4] \| echo i \| endfor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.