Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Vim:如何在文件中只保留选定的文本?_Regex_Vim - Fatal编程技术网

Regex Vim:如何在文件中只保留选定的文本?

Regex Vim:如何在文件中只保留选定的文本?,regex,vim,Regex,Vim,我尝试使用以下命令,但不知何故使用了捷径导致错误:E117:Unknown function:g:ClearAllButMatches。我甚至试着输入:callg:ClearAllButMatches(),但仍然没有用,同样的错误。有什么想法可以让它工作或者其他解决方案吗 function! ClearAllButMatches() let old = @c let @c="" %s//\=setreg('C', submatch(0), 'l')/g %d _ put c

我尝试使用以下命令,但不知何故使用了捷径导致错误:
E117:Unknown function:g:ClearAllButMatches
。我甚至试着输入:
callg:ClearAllButMatches()
,但仍然没有用,同样的错误。有什么想法可以让它工作或者其他解决方案吗

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>
函数!ClearAllButMatches()
让old=@c
让@c=“”
%s/\=setreg('C',子匹配(0),'l')/g
%d_
放c
0d_
让@c=old
端功能
vnoremap c:callg:ClearAllButMatches()

只需移除
g:

vnoremap <leader>c :<c-u>call ClearAllButMatches()<cr>
vnoremap c:调用ClearAllButMatches()

谢谢!完全新手的问题:D