3

I'd like to write the following code:

function Normal(command)
    execute "normal!" a:command
endfunction
call Normal("\<C-O>")
call Normal("\<C-I>")

The first call to Normal succeeds, but the second throws an error:

E471: Argument required

Indeed, you get the same error if you enter the command :norm! ^I with the keystrokes:

:norm!SpaceCtrl-VCtrl-IEnter

I have a vague idea that the problem might be something to do with the fact that a Tab character is whitespace, but I'd like to know more precisely what's going on.

N.B. I've already worked around the issue by adding a count "1\<C-I>", so this is purely out of curiosity.

  • Just to be clear, you already know command can't start with space, you want to know why it can't start with space? – dedowsdi Apr 5 at 12:15
  • @dedowsdi I'm afraid I don't understand your comment. My question is: Why doesn't :execute "normal! \<C-I>" do the same thing as pressing <Ctrl-I> in normal mode? – Rich Apr 5 at 12:26
  • 1
    Well, you knew command of :norm doesn't start with space(which include Tab), you knew \<C-I> is Tab, you knew you can add a count 1 to fix it, it confuses me. – dedowsdi Apr 5 at 12:44
  • @dedowsdi Thanks. Now I understand your comment. No, it wasn't clear to me that {commands} cannot start with a space also implies that {commands} cannot start with the byte 0x9. (But it looks as though you're right that it does.) – Rich Apr 5 at 13:03
  • ...which makes sense when you consider (which I had not) that the execute command might be in a Vimscript file--where tabs might be invisible--not necessarily on the command line. – Rich Apr 5 at 13:11
3

If I guess then what's happening is, that the <c-i> gets expanded to a literal tab before inserting into the typeahead buffer. So Vim basically sees the command :norm! <tab>, which is not a valid command. I don't know a way around and even escaping did not work.

What works, is to use the feedkeys() command, e.g. :call feedkeys("\t", 'tn').

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.