I am using Vim 7.4 and I wish to map the tab key so I can use new combinations to autocomplete arguments in command mode from the current directory

Contents of current directory:

Funwithstrings.cs Funwithstrings.exe Funwithstrings.cs~

Using vim in this directory : I am using following mapping in vim

:map! as <tab>

Now upon trying this in command mode in the manner

:e Fuas.  

I get

:e Fu^I

I.e., ^I two characters instead of special character <tab> instead of one of the filenames-- expected results with tab key. In a different computer I get :e Fu<Tab> - 5 characters.

What am I doing wrong? I am using screen 256 terminal.

  • from what I understand that should work out of the box, if the current directory is correct and you are not using vi mode. – Christian Brabandt Oct 28 '17 at 13:03
  • @christian no it doesn't. Using. Mapped key inserts ^I character literally. in its place instead of autocompleteing file name - - - intended effect of tab. Same for <esc> – mage Oct 28 '17 at 15:20
  • ah, you have been talking about mapped keys. Then that is expected. See the 'wildcharm' option for that. Ah, it is already mentioned in the answer – Christian Brabandt Oct 29 '17 at 8:45

By default with nocompatible, vim sets wildchar to <tab> which enables you to tab complete "out of the box." However, this does not extend to <tab>s produced by mappings.

For example, if we cnoremap as <tab>, pressing as, vim will type literal tabs, which in this case render as ^I.

The solution is to use wildcharm, which is "recognized when used inside a macro" (see :help wildcharm):

set wildcharm=<tab>.

An alternative to making a mapping to <tab> is to just set wildchar or wildcharm to the key you want. This works only for single characters.

  • Using 'set wildcharm=as' returns error E521: Number required after =: wildcharm=as. Whereas with 'cnoremap as <tab>' and 'set wildcharm=<tab>' are able to set 'as' as command line – mage Oct 29 '17 at 12:07
  • i am stikl unable to remap <esc> and other special keys similarly – mage Oct 29 '17 at 12:15
  • I clarified that only single characters are permitted in wildchar/wildcharm. I am not sure what you mean about <esc>.. As far as I know wildcharm=<esc> would work. But I don't recommend mapping <esc> here. – Mass Oct 29 '17 at 16:40

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.