Vimscript-如何检查变量中是否存在字符
我试图创建一个只返回Vimscript-如何检查变量中是否存在字符,vim,match,string-matching,neovim,Vim,Match,String Matching,Neovim,我试图创建一个只返回getcwd()值的一部分的函数 所以,我想要的是 function! FileDir() let file_dir == getcwd() if file_dir "has more than three backlashes" return 'mycommand' else return 'mycommand2' endfunction 因此,我想添加这样的内容:如果getcwd()返回三个以上的
getcwd()
值的一部分的函数
所以,我想要的是
function! FileDir()
let file_dir == getcwd()
if file_dir "has more than three backlashes"
return 'mycommand'
else
return 'mycommand2'
endfunction
因此,我想添加这样的内容:如果getcwd()返回三个以上的目录,比如说:/home/hrq/project folder
,我想向它添加一个特定的if
命令。如果返回两个或更少的文件夹,如just/home/hrq
,我想添加一个else
命令,稍后我将添加这两个命令
所以我想也许我可以检查一下getcwd()
我尝试了match
表达式、max
、len
,但我没能做到。实际上非常简单:
let l:slash = exists('+shellslash') && !&shellslash ? '\' : '/'
if count(getcwd(), l:slash) > 3
...
else
...
endif
谢谢,伙计!它成功了,我很感激!