Vim function doesn't seem to be recognised

2019-08-01 20:19发布

问题:

I copied this in to .vimrc:

function! ClearAllButMatches()
  let old = @c
  let @c=""
  %s//\=setreg('C', submatch(0), 'l')/g
  %d _
  put c
  0d _
  let @c = old
endfunction
vnoremap <leader>c :<c-u>call g:ClearAllButMatches()<cr>

It doesn't seem to work. When I use <leader>c, I am getting this:

E117: Unknown function: g:ClearAllButMatches

Any ideas why its happening?

note:

  1. I have sourced my .vimrc several times.

回答1:

Remove g: from the mapping or add it to the function name