0

I have a script where the first line works:

execute "normal!i\<BS>l"

But this line does not:

let BS = repeat('\<BS>', NUM_CHARS_TO_DELETE)
execute "normal!i" . BS

It seems to just literally insert the \<BS>\<BS>\<BS>\<BS> into the text. What's wrong with the second version?

1
  • 1
    :h literal-string – Matt Jul 16 '20 at 5:28
2

If you surround the \<BS> in the repeat call with double quotes it should work.

let BS = repeat("\<BS>", NUM_CHARS_TO_DELETE)

Single quotes are used for "literal strings", i.e. when you don't want any processing/expansion of the contents.

Double quotes allow for expansion of certain string formats such as the \<xxx> form used in mappings and exe commands.

Valid expansions are shown here: :h expr-quote. It says "Note that double quotes are used" and lists things like \t (tab), \x### (hex digit) as well as, at the end of the list, the \<xxx> form.

1
  • Note, though, that n*backspace is equivalent to normal! nx – D. Ben Knoble Jul 16 '20 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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