vimrc 引用 python3 通过系统命令的路径

vimrc reference python3 path through system command

对于YouCompleteMe插件,我想在我的vimrc中设置参数g:ycm_path_to_python_interpreter为系统python3安装路径

我正在使用 let g:ycm_path_to_python_interpreter = system('which python3') 但是这是无效的,因为 system(..) returns python3 路径的字符串似乎在单独的缓冲区中。我的意思是我看到了

/home/ubuntu/anaconda3/bin/python3

Press ENTER or type command to continue

当我:echo g:ycm_path_to_python_interpreter。我希望路径只是字符串(即 /home/ubuntu/anaconda3/bin/python3)。我该怎么做?

您遇到的问题是 system() 将在命令末尾包含换行符。

你可以通过命令看到:

:let g:ycm_path_to_python_interpreter

它将向您展示:

g:ycm_path_to_python_interpreter     /home/ubuntu/anaconda3/bin/python3^@

(最后的^@代表换行符)

要解决此问题,只需在 system() 调用周围调用 trim()

let g:ycm_path_to_python_interpreter = trim(system('which python3'))