0

I use this plugin https://github.com/hrsh7th/cmp-path for autocompletion, including paths in the command mode. And the problem is that on a tab press the name is completed, but the slash is not appended for directories.

For example, I have a src directory in my current direcotry (for other directories the behavior seems to be the same, so it's not related to this particular name).

When I type: :eSpacesrtab

The command line is populated with the path, src instead of src/.

screenshot of command line with path w/o slash

I've found this question on github, which seems to be exactly the same I'm having (even the config example is the same), but it didn't work for me, for some reason.

I have this in my vimrc:

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
  mapping = cmp.mapping.preset.cmdline(),
  sources = cmp.config.sources({
    {
      name = 'path',
      option = {
        trailing_slash = true
      }
    }
  }, {
    { name = 'cmdline' }
  })
})

Everything seems to be correct, but I have this as the output of the :CmpStatus:

# ready source names
- buffer
- vsnip

# unused source names
- cmdline
- path

# unknown source names
- nvim_lsp

CmpStatus command output

Could someone explain what am I doing wrong?

2

1 Answer 1

0

Figured it out finally. Posting it just in case someone has something similar.

TLDR;

Set option = { treat_trailing_slash = false } for the hrsh7th/cmp-cmdline plugin in addition to the option = { trailing_slash = true } for the hrsh7th/cmp-path one (this should be in your vimrc):

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
  mapping = cmp.mapping.preset.cmdline(),
  sources = cmp.config.sources({
    { name = 'path', option = {  trailing_slash = true } }
  }, {
    { name = 'cmdline', option = {  treat_trailing_slash = false } }
  })
})

The hrsh7th/cmp-cmdline plugin, which I found to use also, has this in its docs (https://github.com/hrsh7th/cmp-cmdline):

treat_trailing_slash: boolean

Default: true

vim.fn.getcompletion can return path items. unfortunately, that items has trailing slash so we don't narrowing with next directory with pressing /.

if you turnd on this option, cmp-cmdline removes trailing slash automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.