farosis / vim

Automatically exported from code.google.com/p/vim
0 stars 0 forks source link

Command-line expression mapping inserts tab literally #308

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

    :cnoremap <expr> <Tab> getcmdpos() == 1 ? 'X' : "\<Tab>"
    :e<Tab>

What is the expected output? What do you see instead?

Expected result after hitting tab is some form of tab completion, actual
result is a literal tab being inserted: :e^I.

What version of the product are you using? On what operating system?

Vim 7.4.560.

Please provide any additional information below.

Consider these two mappings:

    :cnoremap <expr> <Tab> getcmdpos() == 1 ? 'X' : "\<Tab>"
    :cnoremap <expr> <C-D> getcmdpos() == 1 ? 'Y' : "\<C-D>"

The goal is to make <Tab> and <C-D> do something special only when the
cursor is in the first column, otherwise do the default action. This
works with <C-D>, which lists completion matches, but <Tab> inserts a
literal tab instead of completing.

Perhaps related discussion at

http://stackoverflow.com/q/14842987
https://groups.google.com/d/msg/vim_dev/xf5TRb4uR4Y/pUXfsMMC9cwJ

Original issue reported on code.google.com by 676c7...@gmail.com on 1 Jan 2015 at 9:44

GoogleCodeExporter commented 9 years ago
I tend to believe this is no bug, because I believe this is documented at :h 
c_CTRL-I
If you want it to work. set the wildcharm option to <Tab>:
:set wildcharm=<Tab>
For further refining, you need to set the 'wildmode' option, I think :set 
wildmode=list:longest
does what <Tab> does per default in the command line mode

Original comment by chrisbr...@googlemail.com on 1 Jan 2015 at 12:29

GoogleCodeExporter commented 9 years ago
You mean it's documented if we read 'inside a macro' as 'inside macros,
mappings, and abbreviations'?

I find it hard to understand why these mappings should be treated
differently, or why some special setup is necessary to make it work.

Original comment by 676c7...@gmail.com on 1 Jan 2015 at 1:15

GoogleCodeExporter commented 9 years ago
I agree with Christian's answer. Yes, macros include mappings and abbreviations 
(think of them as more persistent special cases).

The reason for the 'wildcharm` option is that usually you want literal 
insertion of <Tab>, as the completion heavily depends on current context (i.e. 
the matches are erratic), so it's unwise to rely on completion in a macro.

Original comment by sw...@ingo-karkat.de on 1 Jan 2015 at 2:16