cmp-path icon indicating copy to clipboard operation
cmp-path copied to clipboard

Allow triggering without trigger characters

Open jemag opened this issue 1 year ago • 4 comments

I would like to be able to replace the default <C-x><C-f> with cmp with path source. However this will not trigger because of the currently configured trigger characters.

Basically I would like to do something like:

vim.keymap.set("i", "<c-x><c-f>", function()
  require("cmp").complete({
    config = {
      sources = {
        {
          name = "path",
          keyword_length = 0,
          keyword_pattern = ".*?",
          trigger_characters = {}
        },
      },
    },
  })
end)

However it does not seem to trigger, despite the empty trigger_characters

jemag avatar Dec 11 '22 17:12 jemag

It would be amazing if we could just trigger filepath completions without mandating a leading / or . This is often very useful for processing scripts that operate on relative paths which can just start with the folder name or the filename rightout, which currently forces xplicit typing of two additional characters ('./') or typing, completing and removing a character afterwards. it would be cool if completion could just happen right away once a character is typed as other path completion sources do it as well.

just adding the entire alphabet to the trigger characters seems to not do the trick, though, I just tried that. I haven't had the chance to look into the lua-code more deeply, so @hrsh7th , if you have any pointers on how to fix that it would be very cool. :)

cherti avatar Oct 09 '23 04:10 cherti

when you look in to the source, the keyword pattern is also hard coded into a path regex. Changing the keyword pattern might not be possible with this plugin. I was trying to understand the regex for a while but i don't get it. I think we need the help of @hrsh7th for this. I'm also very keen on triggering path completion with just a shortcut and nothing else

tummetott avatar Oct 13 '23 07:10 tummetott

We would like to add an option to make the leading slash non-required.

However, with my English skills, I can't think of a good option name. Any ideas?

hrsh7th avatar Oct 13 '23 10:10 hrsh7th

My intuition tells me that i would not want a new option for this. We already have trigger_characters. Is it possible to change to code in a way that the path source is triggered when trigger_characters = {} or trigger_characters = nil? and we would probably also have to adjust keyword_pattern.

If a new option is necessary, I would suggest to call it: always_trigger = true or trigger_with_keymap = true

tummetott avatar Oct 13 '23 11:10 tummetott

any update on this? or any workarounds people have come up with?

GitMurf avatar Feb 06 '24 06:02 GitMurf

Ok this is weird. This PR from a couple years ago seems to do exactly what we all want... triggers the paths from starting quote (" or ') instead of requiring ./ or ../

I wonder what happened? did this decision get later reverted?

https://github.com/hrsh7th/cmp-path/pull/16

GitMurf avatar Feb 06 '24 06:02 GitMurf

Unfortunately no updates. I got used to trigger it with ./ and then later I was deleting the ./ again ... not nice though

tummetott avatar Feb 06 '24 08:02 tummetott

I would also be highly interested in this, but I can't get it to work with changing trigger characters sadly

eekhof avatar Mar 30 '24 11:03 eekhof

Thought i was the only one who disliked having to trigger it with ./. I've tried many workarounds but none worked. Any relevant updates ?

Hexa3333 avatar Jul 12 '24 15:07 Hexa3333

i need this too

shurensha avatar Jul 24 '24 08:07 shurensha

i tried making other trigger characters like @ work but was unable to. but i was able to get " and ' working to suggest cwd completions

https://github.com/shurensha/cmp-path/blob/main/lua/cmp_path/init.lua

shurensha avatar Jul 24 '24 09:07 shurensha