0

I'm using variables for line numbers, and I want to delete a range of lines using these variables. How do I do that?

    let x = 5
    let y = 20
    " I want to delete the range of lines from x to y (i.e., 5-20)
    " I guessed at this, but it doesn't work:
    x,ydelete
    " E15: Invalid expression: ",ydelete"

Extra credit for providing reference(s) to the vim documentation that explains this. (I searched the docs for "variable" but didn't find what I needed)

2

1 Answer 1

1

Use the :execute command, e.g.,

:execute x "," y "delete"

:exe[cute] {expr1} ..
Executes the string that results from the evaluation of {expr1} as an Ex command. Multiple arguments are concatenated...
{expr1} is used as the processed command

[:help execute]

Edit: Per D Ben Knoble's comment, How do I use a variable or return value in option, command, or mapping? addresses this question.

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.