Word completion & character case & smart case

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Word completion & character case & smart case

Thomas-4-2
Hi,

Is there a way to make vim's word completion smarter with respect to
character cases? Let's consider a buffer like:

     - ab
     - ac
     - Ad

Now if I type

     - a<c-p>

vim will present the following possible completions: ab, ac, Ad. But if
I press <c-p> after an upper case A

     - A<c-p>

the possible completions are simply: Ad

Now what I would like to have is:

After a lower case a: ab, ac, ad
After an upper case A: Ab, Ac, Ad

Can this be done somehow by setting some option yet unknown to me?

Cheers,
Thomas.

Reply | Threaded
Open this post in threaded view
|

Re: Word completion & character case & smart case

Tim Chase-2
> Now what I would like to have is:
>
> After a lower case a: ab, ac, ad After an upper case A: Ab,
> Ac, Ad
>
> Can this be done somehow by setting some option yet unknown to
> me?

Not to the best of my knowledge as you describe it.  However, if
you turn on the 'ignorecase' setting (":set ic"), you'll get
auto-completion that will change the case of your initial "a", so
if you have your above example, you'll progressively get "ab",
"ac", "Ad", whether you've typed an "a" or an "A".

I fooled around with something like the following mapping, but
didn't have any luck...the <c-p> kept getting interpreted in
Normal mode, rather than in insert mode.  Bug?  I dunno.

inoremap <c-p> <c-o>:let
isUpperCase=match(getline(".")[col(".")+1],
"[A-Z]")+1<cr><c-p><c-o>:exec "norm g".(isUpperCase?"U":"u")."iw"<cr>

The mapping wouldn't deal, as it currently stands, with multiple
attempts to use <c-p> to keep reselecting new tries, but that
might be feasible after this.

The above mapping *should*, upon pressing <c-p> in insert mode,
set the variable "isUpperCase" according to the last letter you
typed; then perform a genuine <c-p> (where it's currently
failing); then execute the normal mode command to either do
"gUiw" or "guiw" based on the setting of "isUpperCase".  I'd
continue from here, trying to remedy the multiple-tries aspect,
but it's kinda fruitless if I can't get the genuine <c-p> to
behave properly.

Alternatively, if you wanted it based on the first letter of your
word, rather than the most recently typed letter, you can change the

        getline(".")[col(".")+1]

to

        expand("<cword>")[0]

Anybody have any ideas why that <c-p> would be interpreted in
normal mode rather than insert mode?

-tim