views:

356

answers:

1

Let's say I have following typed in my source file.

var myFunction = function() { };

var anotherFunction = function() { };

var test-m

I can now press Ctrl + P and it will show 'myFunction' in the autocomplete list. It's great and very helpful.

But what I want to do is make VIM treat '$' in the same way it treats '-'.

So when I type

var myFunction = function Module$m

and press Ctrl+P and it will show myFunction in autocomplete.

I have looked at this question and tried setting $ as keyword using iskeyword command but it didn't help.

And I know it's possible to do this as I used to have it working before and then I messed up my VIMRC and I am not able to get it work anymore. :(

Your help is appreciated, thanks!

+3  A: 

To make vim use a dollar-sign as a word separator, do:

:set iskeyword-=\$

If wanting the opposite: (to autocomplete words containing a dollar sign, add a literal dollar sign to the current autocomplete match pattern, by doing the opposite:

:set iskeyword+=\$

To find your current iskeyword setting, do:

:set iskeyword?

This will show you a list of ASCII ranges vim considers a single word. Mine looks like:

iskeyword=@,48-57,_,192-255
zen
zen, I tried that. It doesn't work. Any other thoughts/ideas?
SolutionYogi
I'm surprised that didn't work for you. I tested it before posting. Even used your keywords. :( Maybe case sensitivity? `set ic!` ? You are trying to autocomplete "Module$m", right?
zen
try checking what iskeyword is set to by doing `:set iskeyword?` - maybe something is overriding it? You should see a dollar sign in that output. (after +=\$)
zen
Zen, I ran the command and here's what I see. @, 48-57, _, 192-255, $. So $ is present in the list. I really appreciate your help in this matter.
SolutionYogi
ok, try this by the numbers: 1. do vim -u NONE (start up new vim with NO vimrc.) 2. in blank page add line 'module$m' 3. on new line, in insert mode type control-p. (it should autocomplete "module") 4. do `:set iskeyword+=\$` 5. enter insert mode again, type control-p (it should autocomplete 'module$m' -- Verify this works first. If so, another plugin or configuration is overriding default behavior.. Then its a matter of hunting down the plugin or vimrc entry responsible.. Do you know what a binary search is?
zen
Zen, I really appreciate your help in this matter. My problem is not that 'module$m' doesn't show up in autocomplete. My problem is that if I have a word in my file say 'MyLongFunctionName', when I type 'MyNameSpace$M' and press 'Ctrl + P', it should bring up 'MyLongFunctionName' in the autocomplete list. Let me know if it's making sense.
SolutionYogi
And to reply to your comment, it does autocomplete 'module$m' correctly using my current VIMRC. What I want to do is how VIM treats the hyphen '-' when considering auto complete word list.
SolutionYogi
Ok, having re-read your question, I believe you want to FLIP the iskeyword answer I gave. `:set iskeyword-=\$` This will treat dollar-sign as a word SEPARATOR, which is what you need to autocomplete after a dollar sign. This should create the same behavior as after a hyphen. To clarify, characters and ascii values in `iskeyword?` are treated as a single word. You are wanting to autocomplete after the dollar-sign, so it ($) must NOT be in iskeyword. HTH.
zen
Sorry for leading you astray. Your phrase "tried setting $ as keyword using iskeyword command" set me on the wrong path. I've updated the answer and tested it with the autocompletion after hyphen and dollar-sign with expected (same) results.
zen
zen, Thank you! It's working now! I really appreciate your patience and all your help in this matter and I am glad that you are the one getting the bounty!
SolutionYogi
Glad to help. The bounty was an unexpected surprise! Thank you!!
zen