Whenever I want to record complex macro between qa and q, I have to remember that, for instance, I can't use Tab-completion while type some ex command, otherwise the macro will not work.

Have I really to teach myself avoiding Tab-completion (which is so aggressive in my muscle memory) while recording a macro? Or is there a way to make it work?

(BTW, Tab-completion is not even available when I enter Vim by vi -u NONE (but it is if I simply delete my .vimrc file), so maybe the problem is an obvious consequence of how the <Tab> mapping works.)

  • 1
    Try set wc=9 wcm=9. See :h 'wcm. – user938271 Dec 1 '18 at 13:35
  • 1
    9 is the decimal code of the Tab character in the ASCII table. set wc=9 is equivalent to set wc=<Tab> and tells Vim that a Tab character should start a wildcard expansion. set wcm=9 is equivalent to set wcm=<Tab> and tells Vim that a Tab character should start a wildcard expansion, but inside a mapping or a macro. You can give whatever value you want to both options, however they must be identical. – user938271 Dec 4 '18 at 8:58
  • 1
    @user938271, it seems that wcm=9 is enough, just like wc and wcm are not orthogonal and that wcm does something more and nothing less than wc. Can you confirm this? And maybe put it in an answer that I can accept. – Enlico Dec 4 '18 at 13:18
  • 1
    I think that set wcm=9 is enough because <Tab> is the default value of 'wc', and because even if you change its value, the Tab key still starts a wildcard expansion (it may be hard-coded in Vim). Try this: set wc=26 wcm=9 (26 is the decimal code of C-z), then record your macro by pressing C-z instead of Tab. The replay will fail. Now try this: set wc=26 wcm=26, then record your macro by pressing again C-z instead of Tab. This time, the replay will work. – user938271 Dec 4 '18 at 18:35
  • 1
    I don't want to remember this, so I set them both with the same value. This way, when I re-read my vimrc, I have less questions in my mind. I don't want to write an answer because of what the help says at :h c_wildchar: Note: does not work inside a macro, because <Tab> or <Esc> are mostly used as 'wildchar', and these have a special meaning in some macros. I'm not sure there won't be an issue later. Personally, I never had one, but I don't use macros that much. Use it for some time, and if you never encounter any issue, write an answer. It's fine to answer your own question. – user938271 Dec 4 '18 at 18:35

There are no actual questions in your submission but one can be inferred: Why doesn't Tab do wildcard expansion with -u NONE?

-u NONE prevents any vimrc files from being loaded. That results in default values being used for settings and that includes the Vi compatibility setting 'compatible'. This will be enabled per :h 'compatible'. Further, the wildcard expansion key is specified in 'wildchar'. The Vim default is, of course, <Tab> but, per :h 'wc', the Vi default (applicable because of 'compatible') is CTRL-E. Enter Ctrl+E instead of TAB and expansion should work in that scenario.

BTW, wildcard expansion is really an interactive feature while macros are non-interactive. Except for muscle-memory mistakes there shouldn't be any reason command-line Tabs get entered in your macros.

Update: Addressing questions added after I wrote the preceding...between something that will help you avoid typing TAB or something that will make expansion work the latter is the most realistic (though ill-advised, IMO, except for some specific use cases). In fact, @user938271 gave you a hint about this.

I talked about 'wildchar' above. Expansion can't reliably be done in deferred/non-interactive contexts (i.e. a macro/mapping) using this mechanism but there is a related setting 'wildcharm' that provides a means to do so as indicated in the associated help:

'wildcharm' works exactly like 'wildchar', except that it is recognized when used inside a macro 1. ... Normally you'll never actually type 'wildcharm', just use it in mappings [and macros].

wildcharm/wcm is not set by default so we need to do :set wcm=XXX replacing XXX with whatever unused key you prefer, e.g. :set wcm=<Tab>. (Note: 'wcm' is supposed to be set to a number but the <FOO> notation is a legal substitute.) Your issue with macros should be taken care of now.

1Note that Vim documentation has a broader definition of "macro" than some are accustomed to. The term is popularly used most commonly to refer to commands recorded into a register and played back with @. Vim help files, though, sometimes refer to the RHS of key mappings as macros, too.

  • 1
    I'm sorry for having used no ? in the question. Anyway my true question more like How can I have Tab work in recorded command-line macros? – Enlico Dec 4 '18 at 8:46
  • 1
    @Enrico I answered that question. Look at the last line. The only thing I didn't do is show the exact command for Tab (the example is for Ctrl-Z which is the default.). All you need to do is replace <C-Z> with <Tab>: :set wcm=<Tab>. – B Layer Dec 13 '18 at 1:32
  • There. Now it shows the command for Tab, too. – B Layer Dec 13 '18 at 1:38
  • The last two lines of your answer actually answer the question, so I'll accept it. The excerpt you quoted seems useful as well, I'll try to understand how it works. – Enlico Dec 14 '18 at 10:31
  • 1
    Thanks, @Enrico. In retrospect what I excerpted is a bit confusing. The important part is the first sentence. The rest is about mappings not macros so off topic for you question. (Side note: I think the first sentence should say "...inside a macro or mapping"). I'll try to clean it up a bit when I get a chance but it boils down to this: expansion can't reliably be done in deferred/non-interactive contexts (i.e. a macro or mapping) using the normal mechanism but 'wcm' provides a means to do so. – B Layer Dec 14 '18 at 21:10

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.