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

How to set `cmp-zsh` completion source for `:!` commands (`nvim-cmp` stuff)?

Open Dolfost opened this issue 1 year ago • 0 comments

I have wrote this issue to vimstackexchange but got no help.

I have next setup for nvim-cmp cmdline : completion:

cmp.setup.cmdline(':', {
	mapping = cmp.mapping.preset.cmdline(),
	sources = cmp.config.sources({
		-- { name = 'path' },
		{ name = 'zsh' },
	}, {
		{
			name = 'cmdline',
			option = {
				ignore_cmds = { 'Man', '!' }
			}
		}
	})
})

It uses zsh completion for paths and ! command, and cmdline completion for vim : stuff.

How it started: I have been using path and cmdline completion at the start of my journey, but I quickly found out that when I try to :!mv ~/Downdloads/file with spaces.txt ./file.txt I get no space escaping (file\ with\ spaces.txt) from path. So I added the cmp-zsh plugin. In the current setup with zsh completion source I have next problems:

  • When I am writing some : commands I get the zsh and path completion. I want to get only path
  • When I am writing some :!<command> commands, I get no completion for <command> because no shell commands start from !.

SO there is the question: How to make the zsh source be accessible only within :!<command> ... and disable path for :? As You may have noticed, I have already disabled cmdline for :! commands.

The :h nvim-cmp does not contain definition for :! mode. Actually, it says:

*cmp.setup.cmdline* (cmdtype: string, config: cmp.ConfigSchema)
 Setup cmdline configuration for the specific type of command.
 See |getcmdtype()|.
 NOTE: nvim-cmp does not support the `=` command type.

So, there is the getcmdtype() definition:

getcmdtype()						*getcmdtype()*
  	Return the current command-line type. Possible return values
  	are:
  	    :	normal Ex command
  	    >	debug mode command |debug-mode|
  	    /	forward search command
  	    ?	backward search command
  	    @	|input()| command
  	    -	|:insert| or |:append| command
  	    =	|i_CTRL-R_=|
  	Only works when editing the command line, thus requires use of
  	|c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
  	Returns an empty string otherwise.
  	Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.

It looks like there is no :! mode. Then how I can solve the

SO there is the question: How to make the zsh source be accessible only within :!<command> ... and disable path for :?

problem...?

Dolfost avatar Jan 09 '24 11:01 Dolfost